Repository navigation
fix(runtime): skip non-UTF-8 environment variables instead of panicking - #3356
Merged
Merged
Conversation
std::env::vars() panics on any non-UTF-8 value. zsh exports a metafied $_ when the command path contains non-ASCII characters (e.g. 下載), so claw panicked on startup. Use vars_os() and skip entries that are not valid UTF-8.
|
Good fix — this is a real startup crash for anyone running from a non-ASCII path with zsh (the metafied |
|
这个修复很实际:在含 CJK 字符的路径下运行 claw,zsh 导出的非 UTF-8 $_ 会让启动直接 panic,对中文用户来说是相当常见的崩溃场景。改用 env::vars_os() 并跳过非法 UTF-8 条目是正确做法——这三处只查已知的 ASCII 变量名,跳过非 UTF-8 值不会改变行为,还避免了进程直接崩溃。新增的 unix-only 回归测试也覆盖了根因,支持合并。 |
1 similar comment
|
这个修复很实际:在含 CJK 字符的路径下运行 claw,zsh 导出的非 UTF-8 $_ 会让启动直接 panic,对中文用户来说是相当常见的崩溃场景。改用 env::vars_os() 并跳过非法 UTF-8 条目是正确做法——这三处只查已知的 ASCII 变量名,跳过非 UTF-8 值不会改变行为,还避免了进程直接崩溃。新增的 unix-only 回归测试也覆盖了根因,支持合并。 |
Merged
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.
Summary
clawpanics on startup (claw,claw doctor, ...) whenever any environment variable holds a non-UTF-8 value:std::env::vars()panics on non-UTF-8 values. A common real-world trigger: interactive zsh (the macOS default shell) exports a "metafied", non-UTF-8$_when a command is run by relative path from a directory containing non-ASCII characters. Following the README (cd rust && ./target/debug/claw) in a checkout under e.g.~/下載/(any CJK path) crashes immediately.env::vars()snapshots in the runtime (container detection insandbox.rs,RemoteSessionContext::from_envandUpstreamProxyBootstrap::from_envinremote.rs) now useenv::vars_os()and skip entries whose key or value is not valid UTF-8.Anti-slop triage
doctor_tolerates_non_utf8_environment_values(unix-only) fails without the fix.Reproduction
In interactive zsh, from a checkout whose path contains non-ASCII characters:
Or from any shell, by setting a non-UTF-8 value directly:
bash -c 'env "_=$(printf "/tmp/\xe4\xb8\x83\xab")" ./target/debug/claw doctor'Verification
cargo fmt --all --checkcargo test --workspace: all pass excepttools::tests::powershell_runs_via_stub_shell, which fails locally only becausepwshis not installed (same onmain).cargo clippy --workspace: no new warnings in the touched files../target/debug/claw doctorfrom a CJK path in interactive zsh no longer panics.git diff --checkpasses.Compatibility and known gaps
#[cfg(unix)]because it builds a non-UTF-8OsStrfrom raw bytes; Windows behavior is unchanged.Resolution gate