mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 06:05:39 +08:00
Don't count successive "," as literal in brace expansion
This was highly surprising. Fixes #3002.
This commit is contained in:
parent
55ebf4430f
commit
aa58cae601
|
@ -10,6 +10,7 @@ This section is for changes merged to the `major` branch that are not also merge
|
|||
- `set x[1] x[2] a b` is no longer valid syntax (#4236).
|
||||
- For loop control variables are no longer local to the for block (#1935).
|
||||
- A literal `{}` now expands to itself, rather than nothing. This makes working with `find -exec` easier. (#1109, #4632)
|
||||
- Successive commas in brace expansions are handled in less surprising manner (`{,,,}` expands to four empty strings rather than an empty string, a comma and an empty string again). (#3002, #4632).
|
||||
|
||||
## Notable fixes and improvements
|
||||
- `wait` builtin is added for waiting on processes (#4498).
|
||||
|
|
|
@ -514,6 +514,17 @@ echo foo-{}
|
|||
|
||||
echo foo-{$undefinedvar}
|
||||
# Output is an empty line - see <a href="#cartesian-product">the cartesian product section</a>
|
||||
\endfish
|
||||
|
||||
If there is nothing between a brace and a comma or two commas, it's interpreted as an empty element.
|
||||
|
||||
So:
|
||||
\fish
|
||||
echo {,,/usr}/bin
|
||||
# Output /bin /bin /usr/bin
|
||||
\endfish
|
||||
|
||||
To use a "," as an element, <a href="#quotes">quote</a> or <a href="#escapes">escape</a> it.
|
||||
|
||||
\subsection expand-variable Variable expansion
|
||||
|
||||
|
|
|
@ -1354,9 +1354,7 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
|||
break;
|
||||
}
|
||||
case L',': {
|
||||
// If the last character was a separator, then treat this as a literal comma.
|
||||
if (unescape_special && bracket_count > 0 &&
|
||||
string_last_char(result) != BRACKET_SEP) {
|
||||
if (unescape_special && bracket_count > 0) {
|
||||
to_append_or_none = BRACKET_SEP;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -15,11 +15,15 @@ logmsg Bracket expansion
|
|||
echo x-{1}
|
||||
echo x-{1,2}
|
||||
echo foo-{1,2{3,4}}
|
||||
|
||||
echo foo-{} # literal "{}" expands to itself
|
||||
echo foo-{{},{}} # the inner "{}" expand to themselves, the outer pair expands normally.
|
||||
echo foo-{""} # still expands to foo-
|
||||
echo foo-{$undefinedvar} # still expands to nothing
|
||||
|
||||
echo foo-{,,,} # four empty items in the braces.
|
||||
echo foo-{,\,,} # an empty item, a "," and an empty item.
|
||||
|
||||
logmsg Escaped newlines
|
||||
echo foo\ bar
|
||||
echo foo\
|
||||
|
|
|
@ -14,8 +14,10 @@ foo-1 foo-23 foo-24
|
|||
foo-{}
|
||||
foo-{} foo-{}
|
||||
foo-
|
||||
foo- foo- foo- foo-
|
||||
|
||||
foo- foo- foo- foo-
|
||||
foo- foo-, foo-
|
||||
|
||||
####################
|
||||
# Escaped newlines
|
||||
|
|
Loading…
Reference in New Issue
Block a user