Skip to content

fix(glob): expand glob * adjacent to quoted variable expansion#1287

Merged
chaliy merged 1 commit intomainfrom
fix/1277-glob-quoted-var-expansion
Apr 14, 2026
Merged

fix(glob): expand glob * adjacent to quoted variable expansion#1287
chaliy merged 1 commit intomainfrom
fix/1277-glob-quoted-var-expansion

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 14, 2026

Summary

  • Fix glob metacharacters (*, ?, [) not expanding when adjacent to quoted variable expansions like "$var"*.ext
  • Add Token::QuotedGlobWord variant to track words that mix quoted expansions with unquoted glob chars
  • Add Word.has_unquoted_glob flag so the interpreter performs glob expansion while still suppressing IFS splitting

Details

Root cause: The lexer's read_word() promoted the entire token to QuotedWord when 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 QuotedGlobWord token, and allow glob expansion in the interpreter while preserving IFS-splitting suppression.

Both the read_word() path (./"$p"*.ext) and the read_double_quoted_string() continuation path ("$p"*.ext) are fixed.

Test plan

  • New test test_glob_adjacent_to_quoted_variable — verifies for f in ./"$p"*.tmp.html and ls ./"$p"*.tmp.html
  • Existing test_glob_with_quoted_prefix — verifies "$DIR"/* still works
  • All 2437 lib tests pass with zero regressions
  • cargo clippy clean, cargo fmt clean

Closes #1277

…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
@chaliy chaliy merged commit d7cde8e into main Apr 14, 2026
27 checks passed
@chaliy chaliy deleted the fix/1277-glob-quoted-var-expansion branch April 14, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(glob): glob * not expanded when adjacent to quoted variable expansion

1 participant