Permalink
Browse files

Fix crash in ${unset_var//}.

Make sure it respects 'nounset' as well -- I found this bug in mksh.

Addresses issue #58 (Aboriginal Linux.)
  • Loading branch information...
Andy Chu
Andy Chu committed Dec 31, 2017
1 parent 670276e commit 0573fd4effb05fc9aa207e1f57cc0b824ccf045c
Showing with 20 additions and 0 deletions.
  1. +2 −0 core/word_eval.py
  2. +18 −0 spec/var-op-other.test.sh
View
@@ -790,6 +790,8 @@ def _EvalBracedVarSub(self, part, quoted):
val = self._ApplyUnarySuffixOp(val, part.suffix_op)
elif op.tag == suffix_op_e.PatSub: # PatSub, vectorized
val = self._EmptyStrOrError(val)
pat_val = self.word_ev.EvalWordToString(op.pat, do_fnmatch=True)
assert pat_val.tag == value_e.Str, pat_val
View
@@ -35,6 +35,24 @@ echo ${v/c*/XX}
# N-I dash status: 2
# N-I dash stdout-json: ""
### Pattern replacement on unset variable
echo [${v/x/y}]
echo status=$?
set -o nounset # make sure this fails
echo [${v/x/y}]
## STDOUT:
[]
status=0
## BUG mksh STDOUT:
# patsub disrespects nounset!
[]
status=0
[]
## status: 1
## BUG mksh status: 0
## N-I dash status: 2
## N-I dash stdout-json: ""
### Global Pattern replacement with /
s=xx_xx_xx
echo ${s/xx?/yy_} ${s//xx?/yy_}

0 comments on commit 0573fd4

Please sign in to comment.