Skip to content

Commit

Permalink
[osh] Comment on unquoted ${a[*]:-empty} with empty IFS
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jan 3, 2025
1 parent cb85f4c commit 14014d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions osh/word_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,11 +697,21 @@ def _ApplyTestOp(

if tok.id in (Id.VTest_ColonHyphen, Id.VTest_ColonEquals,
Id.VTest_ColonQMark, Id.VTest_ColonPlus):
# The first character of IFS is used as a separator only
# for the double-quoted "$*", or otherwise, a space " " is
# used (for $*, $@, and "$@").
# TODO: We current do not check whether the current $* is
# double-quoted or not. We should use IFS only when $* is
# double-quoted.
if vsub_state.join_array:
sep_width = len(self.splitter.GetJoinChar())
else:
sep_width = 1 # we use ' ' for a[@]

# We test whether the joined string will be empty. When
# the separator is empty, all the elements need to be
# empty. When the separator is non-empty, one element is
# allowed at most and needs to be an empty string if any.
if sep_width == 0:
is_falsey = True
for s in strs:
Expand Down
19 changes: 19 additions & 0 deletions spec/var-op-test.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -794,3 +794,22 @@ ref=a[*]: '' ''
## N-I dash/mksh/zsh STDOUT:
## END:
#### op-test for unquoted ${a[*]:-empty} with IFS=
case $SH in dash) exit ;; esac
IFS=
a=("" "")
argv.py ${a[*]:-empty}
## STDOUT:
[]
## END
## BUG mksh/osh STDOUT:
['empty']
## END
## N-I dash STDOUT:
## END:

0 comments on commit 14014d6

Please sign in to comment.