Permalink
Browse files

Verify that \n \nn and \nnn are accepted for octal escapes.

  • Loading branch information...
Andy Chu
Andy Chu committed Jan 9, 2018
1 parent 5555e82 commit c632dc357caf0e66cb0f58e0658585e53654a33f
Showing with 16 additions and 11 deletions.
  1. +5 −11 core/word_compile.py
  2. +2 −0 gold/dollar-sq.sh
  3. +9 −0 spec/quote.test.sh
View
@@ -42,18 +42,12 @@ def EvalCStringToken(id_, value):
elif id_ == Id.Char_Stop: # \c returns a special sentinel
return None
elif id_ == Id.Char_Octal3: # $'\377'
s = value[1:]
i = int(s, 8)
if i >= 256:
i = i % 256
# NOTE: This is for strict mode
#raise AssertionError('Out of range')
return chr(i)
elif id_ in (Id.Char_Octal3, Id.Char_Octal4):
if id_ == Id.Char_Octal3: # $'\377'
s = value[1:]
else: # echo -e '\0377'
s = value[2:]
elif id_ == Id.Char_Octal4: # \0377 for echo -e
# TODO: Error checking for \0777
s = value[2:]
i = int(s, 8)
if i >= 256:
i = i % 256
View
@@ -33,6 +33,8 @@ echo $'abcd\u006' | od -A n -c | sed 's/ \+/ /g'
echo $'\u6' | od -A n -c | sed 's/ \+/ /g'
#echo $'\0' '\1' '\8' | od -A n -c | sed 's/ \+/ /g'
echo $'\1 \11 \11 \111' | od -A n -c | sed 's/ \+/ /g'
echo $'foo
bar'
View
@@ -158,6 +158,15 @@ echo -n $'\001' $'\377' | od -A n -c | sed 's/ \+/ /g'
001 0O7
## END
### $'' octal escapes with fewer than 3 chars
echo $'\1 \11 \11 \111' | od -A n -c | sed 's/ \+/ /g'
## STDOUT:
001 \t \t I \n
## END
## N-I dash STDOUT:
$ 001 \t \t I \n
## END
### $""
echo $"foo"
# stdout: foo

0 comments on commit c632dc3

Please sign in to comment.