Skip to content

fix(mcp): resolve projects by their non-ASCII folder name (#1827) - #2331

Merged
DeusData merged 2 commits into
mainfrom
fix/issue-1827
Sep 30, 2026
Merged

DeusData merged 2 commits into
mainfrom
fix/issue-1827

Conversation

@DeusData

Copy link
Copy Markdown
Owner

A repo under a non-ASCII path (e.g. .../中文测试仓库) is stored under a
project name whose non-ASCII bytes are hex-transliterated (#571), e.g.
"...-e4b8ade69687e6b58be8af95e4bb93e5ba93". That name is the cache DB
file name, so it is a persisted identity and must stay stable.

Root cause of the "project not found": a bare selector (no path
separator) skipped all normalization, and the #1025 folder-name tail
match bails out early when cbm_validate_project_name() rejects the raw
selector -- which it always does for non-ASCII bytes. So the real
Chinese folder name never reached the lookup that already makes ASCII
folder names work.

Fix: split the name-mapping half of cbm_project_name_from_path() into
cbm_project_name_sanitize() (pure refactor, identical output), and in
normalize_project_arg() encode a bare selector that contains non-ASCII
bytes the same way before the exact/tail lookup. The stored identity is
unchanged (no DB rename, no orphaned indexes); ASCII selectors keep
their existing validation; a selector that collapses to the "root"
fallback is left untouched. Full paths already resolve through
normalize_project_arg -> cbm_project_name_from_path.

Test: mcp::tool_project_arg_resolves_non_ascii_folder_issue1827 indexes
a repo under a CJK folder and selects it by folder name (RED before),
by full path, and asserts an unknown CJK name stays not-found.


Touches src/mcp/mcp.c / tests/test_mcp.c like the #1951 PR; trivial rebase after whichever lands first.

Fixes #1827

A repo under a non-ASCII path (e.g. .../中文测试仓库) is stored under a
project name whose non-ASCII bytes are hex-transliterated (#571), e.g.
"...-e4b8ade69687e6b58be8af95e4bb93e5ba93". That name is the cache DB
file name, so it is a persisted identity and must stay stable.

Root cause of the "project not found": a bare selector (no path
separator) skipped all normalization, and the #1025 folder-name tail
match bails out early when cbm_validate_project_name() rejects the raw
selector -- which it always does for non-ASCII bytes. So the real
Chinese folder name never reached the lookup that already makes ASCII
folder names work.

Fix: split the name-mapping half of cbm_project_name_from_path() into
cbm_project_name_sanitize() (pure refactor, identical output), and in
normalize_project_arg() encode a bare selector that contains non-ASCII
bytes the same way before the exact/tail lookup. The stored identity is
unchanged (no DB rename, no orphaned indexes); ASCII selectors keep
their existing validation; a selector that collapses to the "root"
fallback is left untouched. Full paths already resolve through
normalize_project_arg -> cbm_project_name_from_path.

Test: mcp::tool_project_arg_resolves_non_ascii_folder_issue1827 indexes
a repo under a CJK folder and selects it by folder name (RED before),
by full path, and asserts an unknown CJK name stays not-found.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
…ratchet

normalize_project_arg now decides once which of the selector and its
normalized form to keep and releases the other through the single existing
free(), instead of a separate encode_bare_project_arg with two more raw
frees. cbm_project_name_sanitize drops its redundant "root" early return:
NULL and "" already reach the empty-after-trim "root" return. Behaviour is
unchanged; mcp.c and fqn.c are back at their baselines (784 / 23).

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData
DeusData merged commit 7821a1b into main Sep 30, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-ASCII (e.g. Chinese) directory paths produce an irreversible hex-encoded, non-discoverable project identifier

1 participant