diff --git a/osh/word_eval.py b/osh/word_eval.py index b0a5ad8a1..ba5bd17d7 100644 --- a/osh/word_eval.py +++ b/osh/word_eval.py @@ -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: diff --git a/spec/var-op-test.test.sh b/spec/var-op-test.test.sh index eb5935106..8521f4d6d 100644 --- a/spec/var-op-test.test.sh +++ b/spec/var-op-test.test.sh @@ -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: