mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-12 23:01:16 -03:00
Allow nested square brackets again
Code like echo $list[$var[1]] was producing an error because of nested square brackets. Allow these brackets again. Fixes #5362
This commit is contained in:
@@ -205,17 +205,8 @@ tok_t tokenizer_t::read_string() {
|
||||
expecting.pop_back();
|
||||
} else if (c == L'[') {
|
||||
if (this->buff != buff_start) {
|
||||
if ((mode & tok_modes::array_brackets) == tok_modes::array_brackets) {
|
||||
// Nested brackets should not overwrite the existing slice_offset
|
||||
// mqudsi: TOK_ILLEGAL_SLICE is the right error here, but the shell
|
||||
// prints an error message with the caret pointing at token_start,
|
||||
// not err_loc, making the TOK_ILLEGAL_SLICE message misleading.
|
||||
// return call_error(TOK_ILLEGAL_SLICE, buff_start, this->buff);
|
||||
return this->call_error(tokenizer_error_t::unterminated_slice, this->start,
|
||||
this->buff);
|
||||
}
|
||||
slice_offset = this->buff - this->start;
|
||||
mode |= tok_modes::array_brackets;
|
||||
slice_offset = this->buff - this->start;
|
||||
} else {
|
||||
// This is actually allowed so the test operator `[` can be used as the head of a
|
||||
// command
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
|
||||
####################
|
||||
# Slices
|
||||
fish: Invalid index value
|
||||
echo "$foo[d]"
|
||||
^
|
||||
|
||||
@@ -60,6 +60,8 @@ set -l fooer ''
|
||||
expansion $$foo
|
||||
expansion prefix$$foo
|
||||
|
||||
logmsg Slices
|
||||
|
||||
set -l foo bar '' fooest
|
||||
expansion "$$foo"
|
||||
expansion $$foo
|
||||
@@ -101,6 +103,11 @@ echo $foo[d]
|
||||
echo ()[1]
|
||||
echo ()[d]
|
||||
|
||||
set -l outer out1 out2
|
||||
set -l inner 1 2
|
||||
echo $outer[$inner[2]] # out2
|
||||
echo $outer[$inner[2..1]] # out2 out1
|
||||
|
||||
logmsg Percent self
|
||||
echo %selfNOT NOT%self \%self "%self" '%self'
|
||||
echo %self | string match -qr '^\\d+$'
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
2 prefixbaz prefixquux
|
||||
3 baz quux
|
||||
3 prefixbaz prefixquux prefix
|
||||
|
||||
####################
|
||||
# Slices
|
||||
1 baz quux fooest
|
||||
2 baz quux
|
||||
1 prefixbaz quux fooest
|
||||
@@ -62,6 +65,8 @@
|
||||
# foo = a
|
||||
0
|
||||
|
||||
out2
|
||||
out2 out1
|
||||
|
||||
####################
|
||||
# Percent self
|
||||
|
||||
Reference in New Issue
Block a user