Fix single-quoted strings with embedded newlines, and make heredoc body parts lazy-loadable#3
Open
jdiamond wants to merge 2 commits intowebpro-nl:mainfrom
Open
Conversation
Author
|
Heads up: PR #2 also modifies |
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.
This fixes two related bugs discovered while writing tests for single-quoted strings containing backticks and
$().Bug 1: single-quoted strings with embedded newlines were parsed incorrectly
computeWordPartshad a heuristic — ifword.textcontained a newline, route tobuildHereDocParts(heredoc scanning). The intent was to handle heredoc bodies, but any single-quoted string with a literal newline also triggered this path. The result: backticks and$()inside a multi-line single-quoted string were expanded as real shell substitutions instead of treated as literals.Fixed by splitting the two responsibilities:
computeWordPartsalways usesbuildWordParts(correct shell-word semantics), and a newcomputeHereDocBodyPartshandles heredoc scanning explicitly.Bug 2:
redirect.body.partsalways returnedundefinedHeredoc body words were constructed without a source string, so
word.partsreturnedundefinedimmediately — consumers had no way to access the structural parts via the normal API.Fixed by wiring heredoc body words into the lazy parts system.
WordImplnow accepts an optional per-instance resolver at construction time (alongside the existing static default), and heredoc body words are constructed withcomputeHereDocBodyPartsas their resolver.redirect.body.partsnow works as expected.New tests cover both: multi-line single-quoted strings with backticks and
$(), and the existing heredoc expansion tests now validate throughword.partsrather than calling the internal function directly.