diff --git a/src/hjson_decode.cpp b/src/hjson_decode.cpp index 47be0d9..cc81767 100644 --- a/src/hjson_decode.cpp +++ b/src/hjson_decode.cpp @@ -285,6 +285,11 @@ static std::string _readString(Parser *p, bool allowML) { uffff = uffff * 16 + hex; } _toUtf8(res, uffff); + } else if (p->ch == '\n') { + // Escaped line feed is ignored (line continuation is allowed). + } else if (p->ch == '\r' && _peek(p, 0) == '\n') { + // Escaped line feed is ignored (line continuation is allowed). + _next(p); } else if ((ech = _escapee(p->ch))) { res.push_back(ech); } else { diff --git a/test/assets/JSON28_result.hjson b/test/assets/JSON28_result.hjson new file mode 100644 index 0000000..f9b2fad --- /dev/null +++ b/test/assets/JSON28_result.hjson @@ -0,0 +1,3 @@ +[ + linebreak +] diff --git a/test/assets/JSON28_result.json b/test/assets/JSON28_result.json new file mode 100644 index 0000000..4d89da5 --- /dev/null +++ b/test/assets/JSON28_result.json @@ -0,0 +1,3 @@ +[ + "linebreak" +] diff --git a/test/assets/failJSON28_test.json b/test/assets/JSON28_test.json similarity index 100% rename from test/assets/failJSON28_test.json rename to test/assets/JSON28_test.json diff --git a/test/assets/comments/JSON28_result.hjson b/test/assets/comments/JSON28_result.hjson new file mode 100644 index 0000000..f9b2fad --- /dev/null +++ b/test/assets/comments/JSON28_result.hjson @@ -0,0 +1,3 @@ +[ + linebreak +] diff --git a/test/assets/comments/strings4_result.hjson b/test/assets/comments/strings4_result.hjson new file mode 100644 index 0000000..c5973cb --- /dev/null +++ b/test/assets/comments/strings4_result.hjson @@ -0,0 +1,4 @@ +{ + # escaped \n + key: Look, Mom! No \n's! +} diff --git a/test/assets/comments/strings5_result.hjson b/test/assets/comments/strings5_result.hjson new file mode 100644 index 0000000..15f12ac --- /dev/null +++ b/test/assets/comments/strings5_result.hjson @@ -0,0 +1,4 @@ +{ + # escaped \r\n + key: Look, Mom! No \n's! +} diff --git a/test/assets/comments/strings6_result.hjson b/test/assets/comments/strings6_result.hjson new file mode 100644 index 0000000..2e51fa5 --- /dev/null +++ b/test/assets/comments/strings6_result.hjson @@ -0,0 +1,8 @@ +{ + # escaped \n should not cause line continuation in multiline string + key: + ''' + Look, Mom! \ + No \\n's! + ''' +} diff --git a/test/assets/comments2/JSON28_result.hjson b/test/assets/comments2/JSON28_result.hjson new file mode 100644 index 0000000..f9b2fad --- /dev/null +++ b/test/assets/comments2/JSON28_result.hjson @@ -0,0 +1,3 @@ +[ + linebreak +] diff --git a/test/assets/comments2/strings4_result.hjson b/test/assets/comments2/strings4_result.hjson new file mode 100644 index 0000000..c5973cb --- /dev/null +++ b/test/assets/comments2/strings4_result.hjson @@ -0,0 +1,4 @@ +{ + # escaped \n + key: Look, Mom! No \n's! +} diff --git a/test/assets/comments2/strings5_result.hjson b/test/assets/comments2/strings5_result.hjson new file mode 100644 index 0000000..15f12ac --- /dev/null +++ b/test/assets/comments2/strings5_result.hjson @@ -0,0 +1,4 @@ +{ + # escaped \r\n + key: Look, Mom! No \n's! +} diff --git a/test/assets/comments2/strings6_result.hjson b/test/assets/comments2/strings6_result.hjson new file mode 100644 index 0000000..2e51fa5 --- /dev/null +++ b/test/assets/comments2/strings6_result.hjson @@ -0,0 +1,8 @@ +{ + # escaped \n should not cause line continuation in multiline string + key: + ''' + Look, Mom! \ + No \\n's! + ''' +} diff --git a/test/assets/failStr10a_test.hjson b/test/assets/failStr10a_test.hjson new file mode 100644 index 0000000..5616517 --- /dev/null +++ b/test/assets/failStr10a_test.hjson @@ -0,0 +1,5 @@ +{ + # escaped \n should not cause line continuation in quoteless string + key: Look, Mom! \ +No \\n's! +} \ No newline at end of file diff --git a/test/assets/failStr9a_test.hjson b/test/assets/failStr9a_test.hjson new file mode 100644 index 0000000..4eb19c7 --- /dev/null +++ b/test/assets/failStr9a_test.hjson @@ -0,0 +1,4 @@ +{ + # escaped \r + key: "Look, Mom! \ No \\n's!" +} \ No newline at end of file diff --git a/test/assets/sorted/JSON28_result.hjson b/test/assets/sorted/JSON28_result.hjson new file mode 100644 index 0000000..f9b2fad --- /dev/null +++ b/test/assets/sorted/JSON28_result.hjson @@ -0,0 +1,3 @@ +[ + linebreak +] diff --git a/test/assets/sorted/JSON28_result.json b/test/assets/sorted/JSON28_result.json new file mode 100644 index 0000000..4d89da5 --- /dev/null +++ b/test/assets/sorted/JSON28_result.json @@ -0,0 +1,3 @@ +[ + "linebreak" +] diff --git a/test/assets/sorted/strings4_result.hjson b/test/assets/sorted/strings4_result.hjson new file mode 100644 index 0000000..990a45c --- /dev/null +++ b/test/assets/sorted/strings4_result.hjson @@ -0,0 +1,3 @@ +{ + key: Look, Mom! No \n's! +} diff --git a/test/assets/sorted/strings4_result.json b/test/assets/sorted/strings4_result.json new file mode 100644 index 0000000..db239b0 --- /dev/null +++ b/test/assets/sorted/strings4_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! No \\n's!" +} diff --git a/test/assets/sorted/strings5_result.hjson b/test/assets/sorted/strings5_result.hjson new file mode 100644 index 0000000..990a45c --- /dev/null +++ b/test/assets/sorted/strings5_result.hjson @@ -0,0 +1,3 @@ +{ + key: Look, Mom! No \n's! +} diff --git a/test/assets/sorted/strings5_result.json b/test/assets/sorted/strings5_result.json new file mode 100644 index 0000000..db239b0 --- /dev/null +++ b/test/assets/sorted/strings5_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! No \\n's!" +} diff --git a/test/assets/sorted/strings6_result.hjson b/test/assets/sorted/strings6_result.hjson new file mode 100644 index 0000000..dc9cb66 --- /dev/null +++ b/test/assets/sorted/strings6_result.hjson @@ -0,0 +1,7 @@ +{ + key: + ''' + Look, Mom! \ + No \\n's! + ''' +} diff --git a/test/assets/sorted/strings6_result.json b/test/assets/sorted/strings6_result.json new file mode 100644 index 0000000..db8633f --- /dev/null +++ b/test/assets/sorted/strings6_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! \\\nNo \\\\n's!" +} diff --git a/test/assets/strings4_result.hjson b/test/assets/strings4_result.hjson new file mode 100644 index 0000000..990a45c --- /dev/null +++ b/test/assets/strings4_result.hjson @@ -0,0 +1,3 @@ +{ + key: Look, Mom! No \n's! +} diff --git a/test/assets/strings4_result.json b/test/assets/strings4_result.json new file mode 100644 index 0000000..db239b0 --- /dev/null +++ b/test/assets/strings4_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! No \\n's!" +} diff --git a/test/assets/strings4_test.hjson b/test/assets/strings4_test.hjson new file mode 100644 index 0000000..f1e10aa --- /dev/null +++ b/test/assets/strings4_test.hjson @@ -0,0 +1,5 @@ +{ + # escaped \n + key: "Look, Mom! \ +No \\n's!" +} \ No newline at end of file diff --git a/test/assets/strings5_result.hjson b/test/assets/strings5_result.hjson new file mode 100644 index 0000000..990a45c --- /dev/null +++ b/test/assets/strings5_result.hjson @@ -0,0 +1,3 @@ +{ + key: Look, Mom! No \n's! +} diff --git a/test/assets/strings5_result.json b/test/assets/strings5_result.json new file mode 100644 index 0000000..db239b0 --- /dev/null +++ b/test/assets/strings5_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! No \\n's!" +} diff --git a/test/assets/strings5_test.hjson b/test/assets/strings5_test.hjson new file mode 100644 index 0000000..99fcd98 --- /dev/null +++ b/test/assets/strings5_test.hjson @@ -0,0 +1,5 @@ +{ + # escaped \r\n + key: "Look, Mom! \ +No \\n's!" +} \ No newline at end of file diff --git a/test/assets/strings6_result.hjson b/test/assets/strings6_result.hjson new file mode 100644 index 0000000..dc9cb66 --- /dev/null +++ b/test/assets/strings6_result.hjson @@ -0,0 +1,7 @@ +{ + key: + ''' + Look, Mom! \ + No \\n's! + ''' +} diff --git a/test/assets/strings6_result.json b/test/assets/strings6_result.json new file mode 100644 index 0000000..db8633f --- /dev/null +++ b/test/assets/strings6_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! \\\nNo \\\\n's!" +} diff --git a/test/assets/strings6_test.hjson b/test/assets/strings6_test.hjson new file mode 100644 index 0000000..a8e0f30 --- /dev/null +++ b/test/assets/strings6_test.hjson @@ -0,0 +1,8 @@ +{ + # escaped \n should not cause line continuation in multiline string + key: + ''' + Look, Mom! \ + No \\n's! + ''' +} \ No newline at end of file diff --git a/test/assets/testlist.txt b/test/assets/testlist.txt index cff5e4d..b61369c 100644 --- a/test/assets/testlist.txt +++ b/test/assets/testlist.txt @@ -27,7 +27,6 @@ failJSON21_test.json failJSON22_test.json failJSON23_test.json failJSON26_test.json -failJSON28_test.json failJSON29_test.json failJSON30_test.json failJSON31_test.json @@ -69,7 +68,10 @@ failStr6c_test.hjson failStr6d_test.hjson failStr7a_test.hjson failStr8a_test.hjson +failStr9a_test.hjson +failStr10a_test.hjson int64_test.hjson +JSON28_test.json kan_test.hjson keys_test.hjson mltabs_test.json @@ -84,6 +86,9 @@ root_test.hjson stringify1_test.hjson strings2_test.hjson strings3_test.hjson +strings4_test.hjson +strings5_test.hjson +strings6_test.hjson strings_test.hjson trail_test.hjson windowseol_test.hjson