diff --git a/index.js b/index.js index a90c3cc..07c5750 100644 --- a/index.js +++ b/index.js @@ -179,6 +179,8 @@ function parseString(input, at) { let value = ''; while (input[at] !== type) { if (input[at] === '\\') { + const cr = String.fromCodePoint(0x0D); + const lf = String.fromCodePoint(0x0A); switch (input[++at]) { case '"': case "'": @@ -208,7 +210,18 @@ function parseString(input, at) { value += String.fromCodePoint(parseInt(hexString, 16)); at += 2; break; - } default: + } + case cr: + if (input[at + 1] === lf) { + at += 2; + } else { + at++; + } + break; + case lf: + at++; + break; + default: return [ new ParseError(input, at, 'Unknown escape character') ]; } } else { diff --git a/test/multiline_cr.in b/test/multiline_cr.in new file mode 100644 index 0000000..0d3975a --- /dev/null +++ b/test/multiline_cr.in @@ -0,0 +1 @@ +{ 'foo': ['bar ' 'baz'], 'qux \ quux': 'corge', } \ No newline at end of file diff --git a/test/multiline_cr.out b/test/multiline_cr.out new file mode 100644 index 0000000..06ec905 --- /dev/null +++ b/test/multiline_cr.out @@ -0,0 +1 @@ +{ "foo": ["bar baz"], "qux quux": "corge" } \ No newline at end of file diff --git a/test/multiline_crlf.in b/test/multiline_crlf.in new file mode 100644 index 0000000..0f41ab0 --- /dev/null +++ b/test/multiline_crlf.in @@ -0,0 +1,6 @@ +{ + 'foo': ['bar ' + 'baz'], + 'qux \ +quux': 'corge', +} diff --git a/test/multiline_crlf.out b/test/multiline_crlf.out new file mode 100644 index 0000000..92236ac --- /dev/null +++ b/test/multiline_crlf.out @@ -0,0 +1,4 @@ +{ + "foo": ["bar baz"], + "qux quux": "corge" +} diff --git a/test/multiline_lf.in b/test/multiline_lf.in new file mode 100644 index 0000000..0f41ab0 --- /dev/null +++ b/test/multiline_lf.in @@ -0,0 +1,6 @@ +{ + 'foo': ['bar ' + 'baz'], + 'qux \ +quux': 'corge', +} diff --git a/test/multiline_lf.out b/test/multiline_lf.out new file mode 100644 index 0000000..92236ac --- /dev/null +++ b/test/multiline_lf.out @@ -0,0 +1,4 @@ +{ + "foo": ["bar baz"], + "qux quux": "corge" +}