Repository navigation
syntax: fix parsing a quoted $# in zsh - #1406
Closed
StudentWeis wants to merge 1 commit into
Closed
StudentWeis wants to merge 1 commit into
StudentWeis wants to merge 1 commit into
Conversation
In the short form like "$#", a double quote directly following the
special parameter name was treated as the start of a parameter name,
so $# consumed the quote as a length prefix and failed to parse a name
afterwards, printing just $. Real Zsh treats "$#" as the special
parameter and $#"$foo" as $# followed by a quoted word, so only the
long form like ${#"${foo}"} can start a quoted parameter name.
The same applied to the % and + short prefixes.
Fixes mvdan#1405.
StudentWeis
force-pushed
the
fix-zsh-quoted-dollar-hash
branch
from
August 29, 2026 11:01
1f10f58 to
9b0f0bc
Compare
Owner
|
See: 019025c |
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 #1405.
The problem
In Zsh mode, a double quote directly following
$#in the short formwas treated as the start of a quoted parameter name. The parser then
consumed both the
#and the"as a length prefix, failed to parsea parameter name afterwards, and the expansion collapsed to a bare
$:This silently changes semantics, as
$expands to the shell PID in Zsh,and
zsh -ncannot detect it.Root cause
paramNameStartaccepted"as the start of a parameter name, whichis correct for the long form, where Zsh nested expansions in quotes
like
${#"${foo}"}exist (#1214). But in the short form the"isnever part of the expansion: real Zsh treats
"$#"as the specialparameter, and
$#"$foo"as$#followed by a quoted word:The same applied to the
%and+short prefixes.The fix
Pass whether the expansion is the short form into
paramNameStartandrefuse a leading
"in that case. The long form keeps acceptingquoted parameter names, so
${#"${foo}"}still parses as before.Added parser regression tests for
"$#"and$#"$foo".