Skip to content

Commit

Permalink
[word_eval] Fix bug evaluating ${array[@]::0}.
Browse files Browse the repository at this point in the history
Also add spec test for ${array[@]::}.

Addresses an issue in #653.
  • Loading branch information
Andy Chu committed Apr 17, 2020
1 parent 93116bc commit d688d3f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
6 changes: 3 additions & 3 deletions osh/word_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ def _PerformSlice(val, # type: value_t
strs = [] # type: List[str]
count = 0
while i < n:
if has_length and count == length: # length could be 0
break
s = orig[i]
if s is not None: # Unset elements don't count towards the length.
if s is not None: # Unset elements don't count towards the length
strs.append(s)
count += 1
if has_length and count == length:
break
i += 1

val = value.MaybeStrArray(strs)
Expand Down
19 changes: 19 additions & 0 deletions spec/var-op-slice.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,22 @@ echo ${result//"$0"/'SHELL'}
SHELL
## END
## N-I mksh stdout-json: "\n"

#### ${array[@]::0}
array=(1 2 3)
argv.py ${array[@]::0}
## STDOUT:
[]
## END
## N-I mksh/zsh status: 1
## N-I mksh/zsh stdout-json: ""

#### ${array[@]::}
array=(1 2 3)
argv.py ${array[@]::}
## STDOUT:
[]
## END
## N-I mksh/zsh status: 1
## N-I mksh/zsh status: 1
## N-I mksh/zsh stdout-json: ""
2 changes: 1 addition & 1 deletion test/spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ var-op-patsub() {

var-op-slice() {
# dash doesn't support any of these operations
sh-spec spec/var-op-slice.test.sh --osh-failures-allowed 0 \
sh-spec spec/var-op-slice.test.sh --osh-failures-allowed 1 \
$BASH $MKSH $ZSH $OSH_LIST "$@"
}

Expand Down

0 comments on commit d688d3f

Please sign in to comment.