Repository navigation
Bash: Allow quotes inside command substitutions and parameter expansions in strings - #4223
Open
O1sumitkumar wants to merge 1 commit into
Open
O1sumitkumar wants to merge 1 commit into
O1sumitkumar wants to merge 1 commit into
Conversation
👷 Deploy request for dev-prismjs-com pending review.Visit the deploys page to approve it
|
|
Thanks for working on this. I found another valid Bash case: echo "$( (printf '%s' "inner") )". The proposed parenthesis pattern excludes quotes, and a check of the PR’s pattern matched only the inner "inner" segment—not the full outer string. I added this case alongside the issue’s example and nested parameter/command substitutions, and adjusted the parenthesis matcher to handle quoted strings. In my local v2 checkout, npm test, npm run lint:ci, and npm run typecheck all pass, including the regex safety tests. Would you prefer to incorporate this regression test and fix into #4223, or should I open a focused follow-up PR? |
This branch has not been deployed
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 #4218
Summary
The double-quoted string pattern in
src/languages/bash.jsonly let a command substitution in as\$\([^)]+\), so a"inside the substitution ended the string. One line likewas split into a string that stops at the quote before
&& pwd, then a string that starts at the closing quote of line 1 and runs to the first quote of line 2, and from there on every string was code and every stretch between strings was a string.In Bash,
$(…)and${…}start a new quoting context, so the string pattern is now built by a smalldoubleQuotedString(depth)helper that allows nested double-quoted strings inside both, three levels deep (the same "a few levels cover real scripts" approach as the issue and as the nesting inmikrotik.js):$(then an escape, a nested string, a'…'string, balanced parentheses (so$(( (1 + 2) * 3 ))still works) or any other character, then);${then an escape, a nested string, one level of nested${…}or any other character, then};The
insidegrammar is unchanged, so the tokens inside the string are the same as before.How did you test this change?
tests/languages/bash/nested_quotes_in_string.test(the snippet above plus"${name:-"default"}"and"$(echo "a $(echo "b")") c"). It fails onv2without the change and passes with it.npm ci --ignore-scripts, thennpm test(alltest:*scripts: components, core, identifiers, languages, patterns incl. the exponential/polynomial backtracking checks, plugins, runner) passes;npx eslinton the changed files andnpx tscare clean.v2before it (same order of magnitude, no blow-up).npm run typecheck:tests,npm run benchmark, and the website build.This change was prepared with AI assistance (Grok Bot, an AI agent). I reviewed the diff and the test results.