fixes #1602: escape sequences for characters with code point below 0x10
commit177db3e4dd2011e5df017d6c145d778c6e0d5ee5
authorMichael Ficarra <mficarra@shapesecurity.com>
dateTue 10 Nov 2015, 19:22 (11 years ago)
parente480f5d
examples/passing/StringEscapes.pursnew file+13
@@ -0,0 +1,13 @@
1+module Main where
2+
3+import Prelude ((==), bind)
4+import Test.Assert (assert)
5+
6+singleCharacter = "\0\b\t\n\v\f\r\"\\" == "\x0\x8\x9\xA\xB\xC\xD\x22\x5C"
7+hex = "\x1d306\x2603\x3C6\xE0\x0" == "๐โฯร \0"
8+decimal = "\119558\9731\966\224\0" == "๐โฯร \0"
9+
10+main = do
11+ assert singleCharacter
12+ assert hex
13+ assert decimal
src/Language/PureScript/Pretty/JS.hs+1
@@ -166,6 +166,7 @@ string s = '"' : concatMap encodeChar s ++ "\""
166166 encodeChar '\\' = "\\\\"
167167 encodeChar c | fromEnum c > 0xFFF = "\\u" ++ showHex (fromEnum c) ""
168168 encodeChar c | fromEnum c > 0xFF = "\\u0" ++ showHex (fromEnum c) ""
169+ encodeChar c | fromEnum c < 0x10 = "\\x0" ++ showHex (fromEnum c) ""
169170 encodeChar c | fromEnum c > 0x7E || fromEnum c < 0x20 = "\\x" ++ showHex (fromEnum c) ""
170171 encodeChar c = [c]
171172