fix(glob): expand glob * adjacent to quoted variable expansion#1287
Merged
fix(glob): expand glob * adjacent to quoted variable expansion#1287
Conversation
…ansions In a word like `"$var"*.ext` or `./"$dir"/*.log`, the unquoted glob characters (`*`, `?`, `[`) must still undergo glob expansion even though the word contains a quoted expansion that suppresses IFS splitting. Previously, the lexer's `read_word()` promoted the entire token to `QuotedWord` when `has_quoted_expansion` was true, causing the interpreter to skip glob expansion entirely. This meant `ls ./"$prefix"*.tmp.html` would fail with "No such file". The fix introduces: - `Token::QuotedGlobWord` — a new token variant for words that mix quoted expansions with unquoted glob characters - `Word.has_unquoted_glob` — a flag on the AST Word node that tells the interpreter to perform glob expansion even when `quoted` is true - Detection logic in both `read_word()` and `read_double_quoted_string()` continuation paths Closes #1277
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
*,?,[) not expanding when adjacent to quoted variable expansions like"$var"*.extToken::QuotedGlobWordvariant to track words that mix quoted expansions with unquoted glob charsWord.has_unquoted_globflag so the interpreter performs glob expansion while still suppressing IFS splittingDetails
Root cause: The lexer's
read_word()promoted the entire token toQuotedWordwhen it contained a double-quoted variable expansion (e.g."$p"), causing the interpreter to skip glob expansion on unquoted portions like*.Fix: Detect when a word has both quoted expansions AND unquoted glob chars, emit
QuotedGlobWordtoken, and allow glob expansion in the interpreter while preserving IFS-splitting suppression.Both the
read_word()path (./"$p"*.ext) and theread_double_quoted_string()continuation path ("$p"*.ext) are fixed.Test plan
test_glob_adjacent_to_quoted_variable— verifiesfor f in ./"$p"*.tmp.htmlandls ./"$p"*.tmp.htmltest_glob_with_quoted_prefix— verifies"$DIR"/*still workscargo clippyclean,cargo fmtcleanCloses #1277