summaryrefslogtreecommitdiff
path: root/src/Escaper.coffee
diff options
context:
space:
mode:
authorjeremyfa <contact@jeremyfa.com>2016-02-16 14:22:41 +0100
committerjeremyfa <contact@jeremyfa.com>2016-02-16 14:22:41 +0100
commitaa23be1e0c0ecef7fdeaf69300db86a7aa93ed32 (patch)
treeae1d31a100e7fc6c12ee0b9698fcfb5907d0bd0f /src/Escaper.coffee
parent8d7ac5a28edac061bc95bd15e34031fd0d833599 (diff)
downloadyamljs-aa23be1e0c0ecef7fdeaf69300db86a7aa93ed32.tar.gz
Add more string escaping tests; Fix #54
Diffstat (limited to 'src/Escaper.coffee')
-rw-r--r--src/Escaper.coffee9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/Escaper.coffee b/src/Escaper.coffee
index 1c98d0a..0eefec7 100644
--- a/src/Escaper.coffee
+++ b/src/Escaper.coffee
@@ -7,13 +7,13 @@ class Escaper
# Mapping arrays for escaping a double quoted string. The backslash is
# first to ensure proper escaping.
- @LIST_ESCAPEES: ['\\\\', '\\"', '"',
+ @LIST_ESCAPEES: ['\\', '\\\\', '\\"', '"',
"\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07",
"\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f",
"\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17",
"\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f",
(ch = String.fromCharCode)(0x0085), ch(0x00A0), ch(0x2028), ch(0x2029)]
- @LIST_ESCAPED: ['\\"', '\\\\', '\\"',
+ @LIST_ESCAPED: ['\\\\', '\\"', '\\"', '\\"',
"\\0", "\\x01", "\\x02", "\\x03", "\\x04", "\\x05", "\\x06", "\\a",
"\\b", "\\t", "\\n", "\\v", "\\f", "\\r", "\\x0e", "\\x0f",
"\\x10", "\\x11", "\\x12", "\\x13", "\\x14", "\\x15", "\\x16", "\\x17",
@@ -24,13 +24,13 @@ class Escaper
mapping = {}
for i in [0...@LIST_ESCAPEES.length]
mapping[@LIST_ESCAPEES[i]] = @LIST_ESCAPED[i]
- return mapping
+ return mapping
# Characters that would cause a dumped string to require double quoting.
@PATTERN_CHARACTERS_TO_ESCAPE: new Pattern '[\\x00-\\x1f]|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9'
# Other precompiled patterns
- @PATTERN_MAPPING_ESCAPEES: new Pattern @LIST_ESCAPEES.join('|')
+ @PATTERN_MAPPING_ESCAPEES: new Pattern @LIST_ESCAPEES.join('|').split('\\').join('\\\\')
@PATTERN_SINGLE_QUOTING: new Pattern '[\\s\'":{}[\\],&*#?]|^[-?|<>=!%@`]'
@@ -78,4 +78,3 @@ class Escaper
module.exports = Escaper
-