fix(mcp): resolve projects by their non-ASCII folder name (#1827) - #2331
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.clike the #1951 PR; trivial rebase after whichever lands first.Fixes #1827