Repository navigation
fix(env): skip invalid-identifier env names like GNU bash 5.3 (niubash #102) - #106
Merged
Merged
Conversation
…#102) Windows environments carry entries such as CommonProgramFiles(x86) whose names are not valid shell identifiers. GNU bash binds those into the invisible invalid_env table (variables.c:3307, wired into the export environment by maybe_make_export_env variables.c:5064): they reach child processes but are invisible to set / export -p / declare -p / ${!prefix@}. rubash imported them as ordinary exported variables, so export -p emitted unquoted 'declare -x CommonProgramFiles(x86)=...' lines and sourcing that snapshot died with "syntax error near unexpected token '('". - executor/init.rs + shell/variables.rs: do not import non-identifier env names into the variable store (children still inherit them through the parent environment); drop BASH_FUNC_*%% entries after function import - builtins/declare{,/print}.rs + setattr/print.rs: exclude invalid names from export -p / set / declare -p listings; declare -p INVALID now reports "not found" while declare/export INVALID report "not a valid identifier", byte-identical to bash 5.3.0 - builtins/set.rs + set/unset.rs: share the identifier check, filter the set listing - builtins/complete.rs, executor/expand_braced_special.rs, executor/arrays/executor.rs: ${!prefix@} / ${!prefix*} name lists and compgen -v variable candidates skip invalid names - declare_tests.rs: regression tests for listing and diagnostics
…ygiene guard The Check UTF-8 boundary hygiene step (added in fe16578) has been failing CI since it landed: its own tree contained four unreviewed byte->char widening sites. - executor/command_substitution_pipelines.rs: rewrite the heredoc delimiter scanner at byte level (byte == b'\'', byte.is_ascii_whitespace(), matches!(byte, b';' | b'|' | b'&' | b')')). The previous widened form turned a UTF-8 continuation byte 0x85 into U+0085, which satisfies char::is_whitespace() and truncated a multibyte delimiter mid-character. - scripts/check-utf8-boundary-hygiene.sh: allowlist parser/token_actions.rs `Some(c as char)` — the byte there can only be one of the ASCII structural bytes matched by b'&' | b'|' | b';' | b'<' | b'>'. Verified with a multibyte (CJK) heredoc delimiter through the real executor; cargo test --lib 397 passed; hygiene check clean. 🤖 Generated with [WorkBuddy](https://workbuddy.cn)
This was referenced Sep 16, 2026
caomengxuan666
added a commit
that referenced
this pull request
Sep 16, 2026
…as-char sites - README/README.zh-CN: new "Fixed today" section covering niubash #106 (CRLF line-terminator handling), #107 (-c GNU first-non-option-argument), #108 (type output capture), plus the nameref/history convergence and the debug-instrumentation cleanup from the local batch landing. - check-utf8-boundary-hygiene: extend the execution_misc.rs allowlist entry with the two reviewed byte->char widening patterns introduced by the batch: `out.push(byte as char)` under the 0x20..=0x7e printable-ASCII arm and the octal digit math `b'0' + ((byte >> n) & 0o7)` (always 0x30..0x37) — both can never involve a UTF-8 continuation byte.
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.
Closes unixwin/niubash#102
问题
Windows 环境里有
CommonProgramFiles(x86)这类名字不是合法 shell 标识符的环境变量。GNU bash 5.3 把它们绑定进独立的 invisibleinvalid_env表(variables.c:3307,由 maybe_make_export_env variables.c:5064 合入导出环境):会透传给子进程,但对set/export -p/declare -p/${!prefix@}不可见。rubash 之前把它们当普通导出变量导入,导致:
export -p输出不加引号的declare -x CommonProgramFiles(x86)=...export -p > snapshot; source snapshot用法直接syntax error near unexpected token '('set、${!X*}名单、compgen -v同样泄漏非法名declare -p 'X(BR)'因名字被拒后落进无参全量列举分支,dump 整个变量表修复(对照 GNU bash 5.3.0(1) oracle 逐项验证)
export -p/set列举declare -p INVALIDnot found,rc=1declare INVALID/export INVALID=xnot a valid identifier,rc=1${!prefix*}/${!prefix@}名单BASH_FUNC_*%%export -pexport -p > snap; source snap改动点
executor/init.rs+shell/variables.rs:非法标识符名不导入变量表(子进程通过父环境照常继承);BASH_FUNC_*%%成功导入函数后从env_vars移除builtins/declare.rs/declare/print.rs/setattr/print.rs:列举过滤 + 报错文案对齐(-p走not found,非-p走not a valid identifier)builtins/set.rs+set/unset.rs:共享标识符校验,过滤set列举builtins/complete.rs+executor/expand_braced_special.rs+executor/arrays/executor.rs:${!prefix@}/${!prefix*}名单与compgen -v候选过滤验证
cargo test --lib --locked:397 passed, 0 failed;cargo fmt --check干净Executor真实执行路径)对 WSL/usr/local/bin/bash5.3.0(1) 做 7 组差分,全部一致;含回归单测🤖 Generated with WorkBuddy