Skip to content

[v0.9.0][Windows] search_code content pipeline transcodes UTF-8 through the ANSI codepage — CJK pattern search always returns 0 matches, raw_matches show mojibake #1209

Description

@raypower178

Summary

On Windows (system locale zh-TW, ACP=CP950), search_code never matches CJK patterns even when the pattern verifiably exists in UTF-8 files, and raw_matches[].content returns mojibake with ? replacement characters. The tree-sitter/snippet pipeline (get_code_snippet) handles the same files' CJK content perfectly — only the grep/content pipeline is affected.

Environment

Repro

  1. A UTF-8 Python file contains the string 未來函數 (verified: present in 28 files; file reports "UTF-8 text" for all of them).
  2. Call search_code with {"pattern": "未來函數", "project": "..."}.
  3. Result: total_grep_matches: 0, total_results: 0.

Control A (ASCII pattern, same index): search_code for DualTrackRouter → 55 grep matches, works fine.

Control B (same file, snippet pipeline): get_code_snippet on a function whose docstring contains CJK → CJK returned byte-perfect.

Evidence of ANSI-codepage transcoding

For an ASCII pattern that lands on a line that also contains CJK, raw_matches[].content comes back like:

"content": "                    # ?w?w STEP 2d?G???J???T???J?w?y?{?]DualTrackRouter?^?A"

The original UTF-8 line is ── STEP 2d:載入資訊…(DualTrackRouter)…. This ?-folding pattern is the signature of routing UTF-8 bytes through WideCharToMultiByte/MultiByteToWideChar with CP_ACP (CP950 here): characters unmappable in the ANSI codepage become ?. Since the grep index/content path stores (or compares) the transcoded text, a UTF-8 CJK pattern can never match.

Expected behavior (industry baseline)

Treat file content as UTF-8 by default end-to-end (ripgrep's model: UTF-8 default, BOM sniffing for UTF-16, explicit flag for legacy encodings, U+FFFD for invalid sequences — never the OS ANSI codepage). v0.9.0 already does wide-char correctness for paths (_wfopen, wide-argv); the same treatment is needed for the content pipeline used by search_code.

Related

Adjacent Windows/CJK family: #903 (CJK paths, snippets), #973, #996, #1165 (env vars lossily decoded), #1171 (persistence crash under CJK paths). This one is distinct: it's the content/grep pipeline, not paths — the repo here is indexed under an ASCII junction precisely to avoid the path family, and snippet extraction proves the files themselves are readable.

Impact

Any non-English codebase on Windows (Chinese/Japanese/Korean comments, docstrings, identifiers in strings) silently loses search_code for native-language queries — it returns a clean "0 matches" with no error, so users assume the text simply isn't there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingparsing/qualityGraph extraction bugs, false positives, missing edgespriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.stability/performanceServer crashes, OOM, hangs, high CPU/memoryux/behaviorDisplay bugs, docs, adoption UXwindowsWindows-specific issues

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions