Skip to content

fix: handle non-UTF-8 filenames in git ls-files on Windows#1893

Open
he-yufeng wants to merge 1 commit intoMoonshotAI:mainfrom
he-yufeng:fix/utf8-git-ls-files
Open

fix: handle non-UTF-8 filenames in git ls-files on Windows#1893
he-yufeng wants to merge 1 commit intoMoonshotAI:mainfrom
he-yufeng:fix/utf8-git-ls-files

Conversation

@he-yufeng
Copy link
Copy Markdown

@he-yufeng he-yufeng commented Apr 15, 2026

Summary

On Chinese Windows systems, subprocess.run(..., text=True) uses the system default encoding (GBK), which crashes when git ls-files outputs UTF-8 filenames containing Chinese characters.

This PR:

  • Adds encoding="utf-8" and errors="replace" to all three subprocess.run calls in file_filter.py
  • Guards _parse_ls_files_output against None stdout to prevent the AttributeError: 'NoneType' object has no attribute 'split' cascade

Fixes #1866

Changes

1 file changed, 10 insertions, 2 deletions — all in src/kimi_cli/utils/file_filter.py

Test plan

  • Verified the three subprocess.run calls now specify encoding="utf-8"
  • Needs testing on a Windows machine with Chinese-named files in a git repo
  • @ file completion should work without UnicodeDecodeError

Open with Devin

On Chinese Windows systems the default subprocess encoding is GBK,
which crashes on UTF-8 filenames from git ls-files. Pass explicit
encoding="utf-8" and errors="replace" to all three subprocess.run
calls in file_filter.py.

Also guard _parse_ls_files_output against None stdout so the
AttributeError ('NoneType' has no attribute 'split') doesn't
propagate when the subprocess fails silently.

Fixes MoonshotAI#1866
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

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.

Git仓库中带有中文UTF8文件名时,使用@搜索文件,输入第三个字符后会报错

1 participant