diff --git a/src/builtins/set.rs b/src/builtins/set.rs index b56501422..0d997875c 100644 --- a/src/builtins/set.rs +++ b/src/builtins/set.rs @@ -468,7 +468,7 @@ fn split_var_and_indexes_internal<'a>( l_ind = 1; // first index } else { l_ind = wcstoi_partial(c, crate::wutil::Options::default(), &mut consumed) - .map_err(|_| EnvArrayParseError::InvalidIndex(res.varname.to_owned()))?; + .map_err(|_| EnvArrayParseError::InvalidIndex(c.slice_from(consumed).to_owned()))?; c = c.slice_from(consumed); // Skip trailing whitespace. while !c.is_empty() && c.char_at(0).is_whitespace() { @@ -494,11 +494,14 @@ fn split_var_and_indexes_internal<'a>( let l_ind2: isize; // If we are at the last index range expression, a missing end-index means the range // spans until the last item. + let tmp = consumed; if res.indexes.is_empty() && c.char_at(0) == ']' { l_ind2 = -1; } else { l_ind2 = wcstoi_partial(c, crate::wutil::Options::default(), &mut consumed) - .map_err(|_| EnvArrayParseError::InvalidIndex(res.varname.to_owned()))?; + .map_err(|_| { + EnvArrayParseError::InvalidIndex(c.slice_from(consumed - tmp).to_owned()) + })?; c = c.slice_from(consumed); // Skip trailing whitespace. while !c.is_empty() && c.char_at(0).is_whitespace() { diff --git a/tests/checks/set.fish b/tests/checks/set.fish index 1cb97ec3a..277a3cf7e 100644 --- a/tests/checks/set.fish +++ b/tests/checks/set.fish @@ -951,12 +951,19 @@ while set -e undefined end set -e undefined[x..] -# CHECKERR: set: Invalid index starting at 'undefined' +# CHECKERR: set: Invalid index starting at 'x..]' # CHECKERR: {{.*}}checks/set.fish (line {{\d+}}): # CHECKERR: set -e undefined[x..] # CHECKERR: ^ # CHECKERR: (Type 'help set' for related documentation) +set -e undefined[..y] +# CHECKERR: set: Invalid index starting at 'y]' +# CHECKERR: {{.*}}checks/set.fish (line {{\d+}}): +# CHECKERR: set -e undefined[..y] +# CHECKERR: ^ +# CHECKERR: (Type 'help set' for related documentation) + set -e undefined[1..] set -e undefined[..] set -e undefined[..1]