Bash tool drops non-ASCII characters due to LC_CTYPE=C in shell environment

未关闭 适合新手
#3,601 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
半天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
bash
领域
cli

调研方向

从 bash tool 的子进程启动入口开始,使用报告中的 locale、xxd 和包含非 ASCII 路径的命令重现该问题。验证 shell 在保留预期的最小 shell 启动过程的同时接收到 UTF-8 locale,然后确认命令字符串、文件路径和写入的内容都保留多字节字符。

由索引模型根据 Issue 内容生成。

描述

area:tools

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

  1. Open Copilot CLI
  2. 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.

  1. 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/copilot-cli 的其他 Issue

查看 github/copilot-cli 的全部 Issue

相似的 Issue

更多 Shell/Bash Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。