Bash tool drops non-ASCII characters due to LC_CTYPE=C in shell environment
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 半天
- 新手友好度
- 72/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 冷清
- 技術堆疊
- bash
- 領域
- cli
研究方向
從 bash tool 的子程序啟動入口開始,使用回報的 locale、xxd 和包含非 ASCII 路徑的命令重現問題。驗證 shell 在保留預期的最小 shell 啟動程序的同時收到 UTF-8 locale,然後確認命令字串、檔案路徑和寫入的內容都保留多位元組字元。
由索引模型根據 Issue 內容生成。
描述
Summary
The bash tool in Copilot CLI spawns shells with LANG="" and LC_CTYPE="C". This causes all non-ASCII characters (Chinese, Japanese, Korean, accented Latin, emoji, etc.) to be silently stripped from command strings. File paths containing such characters become unresolvable, and file content written via heredoc or echo loses all multibyte characters.
Environment
- Copilot CLI version: 1.0.49
- OS: macOS (Darwin)
- Shell: bash (spawned by Copilot CLI)
Steps to reproduce
- Open Copilot CLI
- Run any bash command involving non-ASCII characters:
echo "ABC你好DEF" | xxd
Expected: 41 42 43 e4bda0 e5a5bd 44 45 46 0a (UTF-8 bytes preserved)
Actual: 41 42 43 44 45 46 0a — the Chinese characters are gone entirely.
- Attempt to write a file to a path containing non-ASCII directory names:
echo "test" > "/path/to/中文目录/file.txt"
Expected: File created successfully.
Actual: Command hangs indefinitely. The shell appears to attempt resolving a corrupted path (with multibyte characters stripped) and never returns.
Root cause
Running locale inside the bash tool confirms:
LANG=""
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
With LC_CTYPE=C, the shell treats all bytes above 0x7F as invalid and discards them during command-line processing. This affects:
- String literals in commands (echo, printf, heredoc content)
- File path arguments containing non-ASCII characters
- Variable assignments with multibyte content
The same operations succeed when run through Python (which manages its own UTF-8 encoding independent of the shell locale), confirming the filesystem and disk are fine.
Suggested fix
Set LANG=C.UTF-8 (or en_US.UTF-8) when spawning bash subprocesses. This preserves the benefits of a minimal locale (deterministic sort order, no locale-dependent formatting surprises) while correctly handling multibyte characters:
env LANG=C.UTF-8 /bin/bash --norc --noprofile -c "..."
Using --norc --noprofile already avoids loading user shell plugins. Adding a UTF-8 locale on top shouldn't introduce any slowness or side effects.
Impact
This bug makes Copilot CLI effectively unusable for any task involving non-English file paths or content — which is common for users working in CJK languages, or anyone whose project happens to have non-ASCII directory names. The failure mode is particularly bad: commands silently produce corrupted output or hang forever, with no error message indicating the cause.
- 主要語言
- Shell
- 星號
- 11.2k
- 分支
- 1.9k
- 平均合併
- 14 小時 16 分鐘
- 30 天內合併 PR
- 6
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/copilot-cli 的其他 Issue
-
triage
難度 2/5 1-3 小時 新手友好度 72/100
github/copilot-cli#4848 ·
-
area:agents area:mcp
難度 2/5 1-3 小時 新手友好度 72/100
github/copilot-cli#4729 ·
-
area:sessions
難度 2/5 1-3 小時 新手友好度 72/100
github/copilot-cli#4712 ·
-
triage
難度 2/5 1-3 小時 新手友好度 75/100
github/copilot-cli#4638 ·
-
Expose large_output_file_path on TaskShellProgress so clients can read complete shell-task output 未關閉area:tools
難度 2/5 1-3 小時 新手友好度 78/100
github/copilot-cli#4630 · 1 則留言 ·
查看 github/copilot-cli 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 90/100
danielmiessler/LifeOS#2218 ·
-
難度 1/5 1 小時以內 新手友好度 92/100
-
package-update
難度 2/5 1-3 小時 新手友好度 76/100
oSoWoSo/vOid_Community_repOsitory#148 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 68/100
-
chore
難度 1/5 1 小時以內 新手友好度 91/100
alunduil/alunduil-chezmoi#792 ·