Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

fix(corpus): accept a Windows path in corpus add (#2472) (#2501)

Cristian Groza159b94053200
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 11936278f..04026c4ca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -147,6 +147,11 @@ continues in #2427 and #1122, which stay open.
### Fixed
+- `xerj corpus add` accepts a local Windows path such as
+ `F:\Projects\Foo` (#2472). The repo name was the text after the last `/`,
+ so a `\`-separated path stayed whole and was refused as an unsafe repo
+ name; it now names the repo `Foo`, as `F:/Projects/Foo` already did.
+
- `xerj code` shows the part of a long definition that matched the query,
not its first `--full` characters (#2464). The matching text could sit
thousands of characters below the signature, so a hit named the right
diff --git a/engine/crates/xerj-autoindex/src/xc.rs b/engine/crates/xerj-autoindex/src/xc.rs
index c47644b52..fdbde27fb 100644
--- a/engine/crates/xerj-autoindex/src/xc.rs
+++ b/engine/crates/xerj-autoindex/src/xc.rs
@@ -762,6 +762,18 @@ enum XerjignoreCarry {
/// symlink-to-a-dataset into the clone.
const XERJIGNORE_CARRY_MAX_BYTES: u64 = 1024 * 1024;
+/// Repo directory name for a plain-URL or local-path source: its last path
+/// segment without `.git`. #2472: a Windows path (`F:\Projects\Foo`) has
+/// `\`-separated segments, so both separators split.
+fn repo_name_from_source(url: &str) -> String {
+ url.trim_end_matches(['/', '\\'])
+ .rsplit(['/', '\\'])
+ .next()
+ .unwrap_or("")
+ .trim_end_matches(".git")
+ .to_string()
+}
+
/// Filesystem root of a local checkout named by `url`, if `url` is one.
///
/// `git clone` of a filesystem path or a `file://` URL checks out committed
@@ -1105,21 +1117,12 @@ fn run_corpus_add(args: &[String]) -> i32 {
(
resolved,
urls.iter()
- .map(|u| {
- let repo = u
- .trim_end_matches('/')
- .rsplit('/')
- .next()
- .unwrap_or("")
- .trim_end_matches(".git")
- .to_string();
- CorpusSource {
- repo,
- url: u.clone(),
- sha: String::new(),
- declared: String::new(),
- paths: Vec::new(),
- }
+ .map(|u| CorpusSource {
+ repo: repo_name_from_source(u),
+ url: u.clone(),
+ sha: String::new(),
+ declared: String::new(),
+ paths: Vec::new(),
})
.collect(),
)
@@ -5413,6 +5416,29 @@ precedence = ["a", "b"]
assert!(local_checkout_root("file://localhost/no/such/xerj-path-2199").is_none());
}
+ /// #2472: a Windows drive or UNC path names its repo by the last
+ /// `\`-separated segment, as a URL or a Unix path does by its last `/` one.
+ #[test]
+ fn repo_name_from_source_splits_windows_paths() {
+ for (source, repo) in [
+ (r"F:\Projects\Roblox\LunarGame", "LunarGame"),
+ (r"F:\Projects\Roblox\LunarGame\", "LunarGame"),
+ (r"F:\src\widget.git", "widget"),
+ (r"\\server\share\widget", "widget"),
+ ("C:/src/widget/", "widget"),
+ ("/home/me/widget", "widget"),
+ ("https://github.com/xerj-org/xerj.git", "xerj"),
+ ("[email protected]:xerj-org/xerj.git", "xerj"),
+ ] {
+ let name = repo_name_from_source(source);
+ assert_eq!(name, repo, "{source}");
+ assert!(
+ xccode::pathgate::valid_repo_name(&name).is_ok(),
+ "{source} -> {name}"
+ );
+ }
+ }
+
/// #2339: `--own` is explicit. A local path with no LICENSE is not marked
/// own by itself. The marker persists across a re-add, a `--from` file
/// cannot set it, and `xerj corpus own` sets and clears it.