Skip to content

fix(date): preserve spaces in format string from variable expansion#1211

Merged
chaliy merged 1 commit intomainfrom
fix/1203-date-format-wordsplit
Apr 11, 2026
Merged

fix(date): preserve spaces in format string from variable expansion#1211
chaliy merged 1 commit intomainfrom
fix/1203-date-format-wordsplit

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 11, 2026

Summary

  • Fix word-splitting of date +"$var" when the variable contains spaces
  • Root cause: lexer produced Token::Word for mixed-quoted words like +"$fmt", causing IFS field splitting on expansion
  • Fix promotes tokens with double-quoted variable/command expansions from Token::Word to Token::QuotedWord, suppressing field splitting (matches POSIX behavior)

Closes #1203

Test plan

  • test_date_format_var_with_spaces_no_split — verifies date +"$fmt" with spaces produces correct output
  • test_mixed_quote_prefix_var_no_split — verifies generic prefix"$var" pattern preserves spaces
  • Full test suite (2051 tests) passes with no regressions

When a word mixes unquoted literal and double-quoted expansion
(e.g. +"$fmt"), the lexer now promotes it to QuotedWord so the
interpreter suppresses IFS field splitting — matching POSIX
behaviour where double-quoted expansions never undergo splitting.

Previously +"$fmt" with fmt="%B %d, %Y" was word-split into
three arguments ["+%B", "%d,", "%Y"], so only %B was used.

Closes #1203
@chaliy chaliy merged commit ee3f8b5 into main Apr 11, 2026
27 checks passed
@chaliy chaliy deleted the fix/1203-date-format-wordsplit branch April 11, 2026 04:19
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(date): date +"$var" word-splits format when variable contains spaces

1 participant