Permalink
Browse files

Fix evaluation of escaped literals in double quotes.

For example, "\n" is untouched, but "\$" and "\"" are turned into single
characters.

This fixes 3 spec tests in quotes.test.sh.

Addresses issue #49.
  • Loading branch information...
Andy Chu
Andy Chu committed Nov 15, 2017
1 parent d51a8f1 commit 1edc3f763087b1475e7d38984e346e3a7c8f7b89
Showing with 14 additions and 3 deletions.
  1. +3 −0 core/id_kind.py
  2. +9 −1 core/word_eval.py
  3. +2 −2 test/spec.sh
View
@@ -403,6 +403,9 @@ def _Dash(strs):
return [(s, '-' + s) for s in strs]
# TODO: Need to check for binary -o first, before unary -o.
# Then you can fix unary -a too.
def _AddBoolKinds(spec):
spec.AddBoolKind('BoolUnary', {
OperandType.Str: _Dash(list(_UNARY_STR_CHARS)),
View
@@ -851,7 +851,15 @@ def _EvalWordPart(self, part, quoted=False):
val = part.token.val
assert len(val) == 2, val # e.g. \*
assert val[0] == '\\'
s = val[1]
c = val[1]
if quoted:
# https://www.gnu.org/software/bash/manual/bash.html#Double-Quotes
if c in ('$', '`', '"', '\\'):
s = c
else:
s = val
else:
s = c
return [runtime.StringPartValue(s, False, False)]
elif part.tag == word_part_e.SingleQuotedPart:
View
@@ -229,9 +229,9 @@ subshell() {
${REF_SHELLS[@]} $OSH "$@"
}
# Need to fix $ tokens, and $''
# Need to implement $'' escaping
quote() {
sh-spec spec/quote.test.sh --osh-failures-allowed 4 \
sh-spec spec/quote.test.sh --osh-failures-allowed 1 \
${REF_SHELLS[@]} $OSH "$@"
}

0 comments on commit 1edc3f7

Please sign in to comment.