Repository navigation
rubash#3605 run-nquote: don't count expansion-introduced newlines as input lines - #3678
Merged
Merged
Conversation
…input lines GNU pushes alias-expansion text onto the input (parse.y:2055 push_string) and consumes it through shell_getc; the line_number bump fires only inside yy_readline_get on a REAL input fetch (parse.y:2504). A newline inside an alias value is therefore a command separator but not a line advance: every command born from one expansion stamps the alias word's line, and the next real input line advances from there. Rubash splices expansion text into a flat buffer the batch lexer counts normally, inflating stamps by the number of expansion newlines (nquote4.sub reported 'line 8' where GNU reports 'line 6'). - alias_stream: expand_aliases_in_source_marked returns the expanded text plus ascending byte offsets of newlines the splice introduced; splice_alias_value records each spliced '\n' char offset and shifts recorded marks by the same delta bounds get (streaming MainAliasScanner drops them — its String-only consumers never see expansion text). - lexer: push_line_counted gates the line_number bump in push_main_line/feed_awaiting_body; the tokenize_with_heredocs split loop marks a piece uncounted when its terminating newline's byte offset is in the set. tokenize_comsub_body_with_origin_marked / tokenize_with_initial_posix_marked carry the set through. - script_driver/execution.rs: expand_group_aliases_marked + run_source_with_line_offset_marked plumb the set from both batch expansion sites (run_history_group, run_source_groups); reuse is refused when marks are non-empty (certified feeder tokens have inflated stamps). Verified vs GNU bash 5.3.20: nquote4.sub shape plus mid-line, value-trailing-newline and multi-newline variants match byte-for-byte; niubash gate run-nquote PASS, run-alias/run-errors diffs unchanged (pre-existing class items). tests/issue3605_alias_expansion_lines.rs pins the stamp rule on three shapes. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This was referenced Nov 15, 2026
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿:
F 点:无 未跑/VOID 的腿:无 |
caomengxuan666
marked this pull request as ready for review
November 16, 2026 08:14
This was referenced Nov 16, 2026
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
Refs #3605 (class B,
run-nquote).GNU pushes alias-expansion text onto the input (
parse.y:2055 push_string) and consumes it throughshell_getc; theline_numberbump fires only insideyy_readline_geton a REAL input fetch (parse.y:2504). A\ninside an alias value is therefore a command separator but not a line advance: every command born from one expansion stamps the alias word's line, and the next real input line advances from there.Rubash splices expansion text into a flat buffer the batch lexer counts normally, inflating stamps by the number of expansion newlines (
nquote4.subreportedline 8where GNU reportsline 6).Changes
src/lexer/alias_stream.rs:expand_aliases_in_source_markedreturns the expanded text plus ascending byte offsets of newlines the splice introduced;splice_alias_valuerecords each spliced\nchar offset and shifts recorded marks by the same deltaboundsget. The streamingMainAliasScannerdrops them — its String-only consumers never see expansion text.src/lexer/mod.rs:push_line_countedgates theline_numberbump inpush_main_line/feed_awaiting_body; thetokenize_with_heredocssplit loop marks a piece uncounted when its terminating newline's byte offset is in the set.tokenize_comsub_body_with_origin_marked/tokenize_with_initial_posix_markedcarry the set through.src/script_driver.rs,src/builtins/source/execution.rs:expand_group_aliases_marked+run_source_with_line_offset_markedplumb the set from both batch expansion sites (run_history_group,run_source_groups). Token reuse is refused when marks are non-empty — certified feeder tokens have inflated stamps (whitelist narrowing; a false negative costs the fresh re-lex, never semantics).Verification
nquote4.subshape plus mid-line (x=1; foo), value-trailing-newline, and multi-newline variants — byte-for-byte identical includingline N: quux: command not foundstamps.run-nquotePASS (was FAIL);run-alias/run-errorsdiffs unchanged (pre-existing class items owned by other classes),run-type/run-quotePASS.tests/issue3605_alias_expansion_lines.rs: 3 regressions pin the stamp rule.cannot execute binary fileenvironmental failures (fix(executor): admit Mach-O images in the exec gates on macOS (Refs #3585) #3586).Scope note
expand_comsub_alias_bodies($(/${pre-pass) newlines are not tracked — a second-order gap; comsub bodies re-lex at runtime with their own line base.