diff --git a/osh/word_parse.py b/osh/word_parse.py index 95c8d63818..46856d0032 100644 --- a/osh/word_parse.py +++ b/osh/word_parse.py @@ -264,19 +264,19 @@ def _ReadVarOpArg2(self, arg_lex_mode, eof_type, empty_ok): def _ReadSliceVarOp(self): # type: () -> suffix_op.Slice """ + Looking token after first ':' + ArithExpr? (':' ArithExpr? )? '}' """ - # Looking token after first ':' - self._SetNext(lex_mode_e.Arith) - self._GetToken() + self._NextNonSpace() cur_id = self.token_type - begin = arith_expr.EmptyZero # type: arith_expr_t - if cur_id != Id.Arith_Colon: # A pun for Id.VOp2_Colon + if cur_id in (Id.Arith_RBrace, Id.Arith_Colon): # ${a:} or ${a::} + begin = arith_expr.EmptyZero # type: arith_expr_t + else: begin = self.a_parser.Parse() - cur_id = self.a_parser.CurrentId() - #log('after begin %s', Id_str(cur_id)) + cur_id = self.a_parser.CurrentId() # advance if cur_id == Id.Arith_RBrace: # ${a:1} or ${@:1} no_length = None # type: Optional[arith_expr_t] # No length specified diff --git a/spec/var-op-slice.test.sh b/spec/var-op-slice.test.sh index 57ec455cf9..ffdeafd152 100644 --- a/spec/var-op-slice.test.sh +++ b/spec/var-op-slice.test.sh @@ -350,7 +350,7 @@ argv.py "${s:0:0}" ['1', '2', '3'] ## END -#### Inconsistent - ${array[@]:} is not allowed but ${array[@]: } is +#### ${array[@]:} vs ${array[@]: } - bash and zsh inconsistent $SH -c 'array=(1 2 3); argv.py ${array[@]:}' $SH -c 'array=(1 2 3); argv.py space ${array[@]: }' @@ -363,6 +363,13 @@ $SH -c 's=123; argv.py space ${s: }' ['space', '123'] ## END +## OK osh STDOUT: +['1', '2', '3'] +['space', '1', '2', '3'] +['123'] +['space', '123'] +## END + ## BUG mksh STDOUT: ['space', '123'] ## END