Skip to content

Commit

Permalink
[osh/arith] Fix bug with empty string and shopt -s eval_unsafe_arith.
Browse files Browse the repository at this point in the history
Addresses issue reported in #653.
  • Loading branch information
Andy Chu committed Apr 5, 2020
1 parent 4c4f92e commit e379b61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions osh/sh_expr_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ def _StringToInteger(self, s, span_id=runtime.NO_SPID):

# note: 'test' and '[' never evaluate recursively
if self.exec_opts.eval_unsafe_arith() and self.parse_ctx:
# Special case so we don't get EOF error
if len(s.strip()) == 0:
return 0

# For compatibility: Try to parse it as an expression and evaluate it.

arena = self.parse_ctx.arena
Expand Down
11 changes: 11 additions & 0 deletions spec/arith.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,14 @@ status=0
## N-I dash status: 2
## N-I dash stdout-json: ""

#### eval_unsafe_arith on empty string
shopt -s eval_unsafe_arith
a=''
echo $(( a ))

a2=' '
echo $(( a2 ))
## STDOUT:
0
0
## END

0 comments on commit e379b61

Please sign in to comment.