Repository navigation
Conversation
state_delimiter handed a leading ${VAR} to state_unquoted before the
variable was looked up, so an unset variable left an empty buffer that
was pushed as an empty argument. Let substitute_variable report whether
the variable was set and enter the unquoted state only in that case.
Fixes uutils#15773
sylvestre
reviewed
Oct 26, 2026
| Some(c) if ASCII_WHITESPACE_CHARS.contains(&c) => { | ||
| self.skip_one()?; | ||
| } | ||
| Some(DOLLAR) => { |
Contributor
There was a problem hiding this comment.
maybe add a short comment why: an unset variable must not start a word
Contributor
Author
There was a problem hiding this comment.
Thanks, added a short comment in c476c8f.
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 #15773
In
env -S, a${VAR}at the start of a word was handed to the unquoted state before the variable was looked up. IfVARwas unset, nothing was added, but the word was already open, so an empty argument was pushed at the next blank,\_or\c.env -S 'printf [%s] a ${U}'printed[a][],${U}#c dno longer treated#as the start of a comment, and a command that began with an unset variable failed with an empty program name.substitute_variablenow returns whether the variable was set, and the delimiter state enters the unquoted state only in that case. An unset variable on its own adds no word, which matches the behavior described in the issue. Text next to the variable (x${U},${U}x), quoted forms ("${U}",""${U},${U}"") and a variable that is set but empty behave as before.I added unit tests for the split iterator (an unset variable on its own, and next to other text or quotes) and one
test_env.rstest that checks the arguments withprintf, so it does not need an external interpreter. The two tests for the bug fail on current main and pass with this change.cargo fmt,cargo clippy --all-targets -- -D warnings,cargo test -p uu_envandcargo test --test tests test_envpass. Tested on macOS only.