Repository navigation
fix(eval): render the data-double-quote marker back to source before re-parsing - #114
Merged
Merged
Conversation
…re-parsing eval hands the string_list of its expanded arguments straight to parse_and_execute (builtins/eval.def:49 -> evalstring), so the text is read as shell source a second time. In GNU the text that reaches that second parse comes out of expand_word_internal's single-quote arm (subst.c:11882) via string_extract_single_quoted (subst.c:1088) and remove_quoted_escapes (subst.c:11902 -> 4901 -> dequote_escapes:4692), which only strips CTLESC-CTLESC and CTLESC-CTLNUL pairs. A `"` written inside single quotes therefore stays a bare quote character and delimits again on reparse. Rubash carries that same character as the data-double-quote marker (\x18) so the expansion walker does not treat it as a delimiter, and eval_source_for_reparse already rendered \x17, \x1f and the ANSI-C markers back to source -- but not \x18. The marker survived into the reparse text, so the quotes became literal data for the inner command: eval 'd='\''/x'\''; mkdir -p "$d"' mkdir: cannot create directory '"/x"': No such file or directory That shape is what agent wrappers emit (Hermes escapes every command as `eval '<cmd with '\'' escapes>'` to source a session snapshot, cd, run, and write back a cwd marker), so mkdir/write_file and every other external command failed. niubash #124. tests/issue124_eval_quote_marker.rs pins the fixed semantics plus the controls that never regressed (fully single-quoted arguments, balanced literal quote pairs).
This was referenced Sep 17, 2026
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.
Fixes unixwin/niubash#124.
Symptom
In niubash v1.1.4 an external command that arrives wrapped in
eval '<cmd>'receives its inner single-quoted argument as literal characters:Hermes and other agent frameworks wrap every command that way —
eval 'source snap; cd; <cmd with '\'' escapes>; write cwd'— sowrite_filefailed 100% of the time. Minimal shape:Root cause
evalhands thestring_listof its expanded arguments straight back toparse_and_execute(builtins/eval.def:49→evalstring), so the text is read as shell source a second time. In GNU, the text that reaches that second parse comes out of the single-quote arm ofexpand_word_internal(subst.c:11882) via:string_extract_single_quoted(subst.c:1088) — raw substring copy, no dequoting;remove_quoted_escapes(subst.c:11902→4901→dequote_escapesatsubst.c:4692) — strips onlyCTLESC-CTLESCandCTLESC-CTLNULpairs.So a
"written inside single quotes stays a bare quote character and delimits again on the reparse. The'\''idiom concatenates a"…"segment back into the argument, and that segment's quotes become syntax on the second parse — which is exactly the intended behaviour.Rubash stores that same character as its data-double-quote marker (
\x18) so the expansion walker does not treat it as a delimiter.eval_source_for_reparsealready rendered\x17,\x1fand the ANSI-C quote markers back to source, but not\x18. The marker therefore leaked into the reparse text as literal data and the quotes reached the child process verbatim.Fix
src/executor/execution_misc.rs— restore\x18to a bare"ineval_source_for_reparse, with a comment recording the GNU call chain above.Tests
tests/issue124_eval_quote_marker.rs(7 cases). The first four fail without the.replace('\x18', "\"")line and pass with it; the remaining three pin behaviour that never regressed:eval_single_quote_escape_concat_keeps_double_quotes_as_syntaxx y/rc=0eval_quoted_variable_inside_concat_is_one_wordeval_quoted_variable_printf_has_no_literal_quotes"eval_hermes_wrapper_payload_shapefully_single_quoted_eval_argument_still_delimitsbalanced_literal_double_quotes_group_the_inner_worda bdelimiters_inside_eval_text_pair_across_the_boundaryrc=0Verification
cargo test --test issue124_eval_quote_marker— with the fix removed:3 passed; 4 failed; restored:ok. 7 passed."inside the eval text, and a bare\"inside the eval text); they will be tracked on their own.