Conform redirections: ambiguous redirect + noclobber (batch80) - #278
Merged
Conversation
A redirection target undergoes brace, parameter, command, and arithmetic
expansion followed by word splitting and pathname expansion. bash requires
the result to be exactly one word; anything else (an unset or empty variable,
a value that splits on IFS, a glob matching several files, a brace expansion)
is an "ambiguous redirect" (redir.c redirection_expand).
gnash expanded redirect targets with expand_no_split, joining all fields into
a single literal word, so `cat < $z' with z="a b" tried to open a file named
`a b' instead of reporting the ambiguity. Add expand_redir_target, which runs
the full expand_args pipeline and errors with the original unexpanded word text
when the result is not a single word. Apply it to every filename redirection
(<, >, >|, >>, <>, &>, &>>, and the {var}<file form) and to the fd-dup
operators (<&word / >&word), which likewise reject a word that splits to zero
or several fields.
Closes #277.
`set -o noclobber' / `set -C' / `-C' was recognized as an option name but had no effect: `>' truncated existing files unconditionally. Wire opt_noclobber through set/set -o, $-, and $SHELLOPTS, and honor it when opening a truncating output redirection. open_redir_output mirrors bash's noclobber_open (redir.c): under noclobber a clobbering redirect (`>' or `&>', not the overriding `>|') refuses to overwrite an existing regular file with `cannot overwrite existing file', creates a missing file exclusively, and writes to a non-regular file (device, fifo, /dev/null) without truncating. Append (`>>', `&>>') and read-write (`<>') redirections are unaffected.
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
Two coherent redirection-conformance fixes surfaced by
redir.tests(byte-diff 186 → 178, no regressions elsewhere).1. Ambiguous redirect (closes #277)
A redirection target is expanded (brace, parameter/command/arithmetic substitution, word splitting, pathname expansion) and bash requires the result to be exactly one word; zero or multiple words is an
ambiguous redirect. gnash usedexpand_no_split(joining fields into one literal word), soz="a b"; cat < $zopened a file literally nameda b.New
expand_redir_targetruns the full pipeline and errors with the original unexpanded word text when the result isn't a single word. Applied to every filename redirection (<,>,>|,>>,<>,&>,&>>,{var}<file) and to the fd-dup operators (<&word/>&word).2. noclobber
set -o noclobber/set -C/-Cwas recognized but had no effect. Wireopt_noclobberthroughset/set -o,$-, and$SHELLOPTS, and honor it when opening a truncating output redirection.open_redir_outputmirrors bash'snoclobber_open: a clobbering redirect (>/&>, not the overriding>|) refuses to overwrite an existing regular file (cannot overwrite existing file), creates a missing file exclusively, and writes to a non-regular file (device, fifo, /dev/null) without truncating.>>,&>>, and<>are unaffected.Testing
redir186 → 178, zero regressions across the full test suite