Repository navigation
fix: entry-encode imported environment values at the import funnel (Refs #2884) - #3002
Merged
Merged
Conversation
Golden cells from the #2879 sweep env-import battery, expectations captured byte-for-byte from GNU bash 5.3.20: bare U+E314 eaten by declare -p, U+E400+U+E314 pair collapsing to one char, raw ESC byte losing its $'...' quoting — plus payload/tab-newline controls, the BASH_FUNC source channel, and a nested-shell round trip. Fail-first on base fb96e74: 3 passed / 4 failed.
…efs #2884) GNU variables.c:368 initialize_shell_variables stores environ verbatim because GNU has no transport domain; this engine does, and environment import was the one value entry that skipped the encoding every other channel applies (stdin lines, read input, comsub output all enter through bytes_to_shell_text / push_escaped_text_with_carriers). Executor::new_inner now routes the imported map through env_helpers::entry_encode_imported_env before VarTable::from_values, per consuming channel: __RUBASH_* transport verbatim, BASH_FUNC_*%% bodies take the source encoding (escape_marker_zone_chars, the bytes_to_script_text parity), user values take the data encoding (new substitution_metadata::entry_encode_value_text, the bytes_to_shell_text parity). The process_env_snapshot field keeps the raw values for the Drop-time verbatim restore.
caomengxuan666
marked this pull request as ready for review
November 7, 2026 17:30
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.
Refs #2884
UNVERIFIED-BY-CAPTAIN — lane self-verification in the lane REPORT; captain re-check pending.
Root cause
Process-environment import was the one value entry point that stored incoming values without entry encoding. The engine's stored spelling is a transport domain (carrier protocol,
src/executor/markers.rs: C0/PUA codepoints standing in for GNU's CTLESC/CTLNUL), and every other value channel entry-encodes at its boundary — stdin lines,readinput, comsub output and assignment RHS all enter throughbytes_to_shell_text/push_escaped_text_with_carriers. Environment import fedprocess_env_pairs()straight intoVarTable::from_values, so bare registry chars in inherited user values were live protocol downstream:declare -pprintsv=""(display decoder's guard arm eats it)${#v}= 1)declare -pprints the raw ESC inside plain quotesdeclare -p→v=$'A\EB'GNU anchor:
variables.c:368 initialize_shell_variablesstores environ verbatim — GNU has no transport domain, so verbatim storage is only correct here once the value is in stored spelling.Fix (one mechanism, at the single import funnel)
Executor::new_inner— the only constructor funnel (the apiSessionincluded) — now routes the imported map through a newenv_helpers::entry_encode_imported_envbeforeVarTable::from_values, encoding per consuming channel:__RUBASH_*names: the shell's own cross-process transport — interpretation is deliberate, values pass verbatim (the issue's scoping note).BASH_FUNC_*%%entries: consumed by the function-source channel (import_exported_functions_from_envtokenizes the value as source), so they take the source encoding (escape_marker_zone_chars, thebytes_to_script_textparity); raw carrier bytes in a body keep the lexer meaning they would have in a script file.substitution_metadata::entry_encode_value_text, thebytes_to_shell_textvalid-text arm (push_escaped_text_with_carriers: marker-zone chars E400-escaped, raw carrier bytes as raw-byte marker pairs), with a no-change fast path.The
process_env_snapshotfield keeps the raw values — the Drop-time restore writes them back to the process environment verbatim; only the table import is encoded. Respawn-state file entries (rubash-written transport, spliced after import) are untouched.Pins
tests/issue2884_env_import_entry_encoding_regressions.rs(7 tests; expectations captured byte-for-byte from GNU bash 5.3.20): the three golden cells, lone-payload-char and tab/newline controls, the BASH_FUNC source channel, and a nested-shell round trip. Fail-first on basefb96e741: 3 passed / 4 failed (the 4 failures are exactly the golden cells + round trip; controls pass). Plus a unit test inenv_helperspinning the per-channel encoding contract.本 PR 删除了什么
Nothing deleted: +113/−5 across three source files (one widened visibility,
escape_marker_zone_chars→pub(crate)) plus the new pin file. No ledger change (no new public surface — both new helpers arepub(in crate::executor)/pub(crate));src/lexer/continuation.rsuntouched.