From 2a03b527d6b1b5fd00e1a8c3a2572eee992d8364 Mon Sep 17 00:00:00 2001 From: trobro Date: Sat, 1 May 2021 12:39:25 +0200 Subject: [PATCH 1/5] allow line continuation --- src/hjson_decode.cpp | 5 +++++ 1 file changed, 5 insertions(+) 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 { From 9222452737ff94bdb1ab44d9ccf19edded01d009 Mon Sep 17 00:00:00 2001 From: trobro Date: Sat, 1 May 2021 12:41:50 +0200 Subject: [PATCH 2/5] updated tests --- test/assets/JSON28_result.hjson | 3 +++ test/assets/JSON28_result.json | 3 +++ test/assets/{failJSON28_test.json => JSON28_test.json} | 0 test/assets/comments/JSON28_result.hjson | 3 +++ test/assets/comments/strings4_result.hjson | 4 ++++ test/assets/comments/strings5_result.hjson | 4 ++++ test/assets/comments2/JSON28_result.hjson | 3 +++ test/assets/comments2/strings4_result.hjson | 4 ++++ test/assets/comments2/strings5_result.hjson | 4 ++++ test/assets/failStr9a_test.hjson | 4 ++++ test/assets/sorted/JSON28_result.hjson | 3 +++ test/assets/sorted/JSON28_result.json | 3 +++ test/assets/sorted/strings4_result.hjson | 3 +++ test/assets/sorted/strings4_result.json | 3 +++ test/assets/sorted/strings5_result.hjson | 3 +++ test/assets/sorted/strings5_result.json | 3 +++ test/assets/strings4_result.hjson | 3 +++ test/assets/strings4_result.json | 3 +++ test/assets/strings4_test.hjson | 5 +++++ test/assets/strings5_result.hjson | 3 +++ test/assets/strings5_result.json | 3 +++ test/assets/strings5_test.hjson | 5 +++++ test/assets/testlist.txt | 5 ++++- 23 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 test/assets/JSON28_result.hjson create mode 100644 test/assets/JSON28_result.json rename test/assets/{failJSON28_test.json => JSON28_test.json} (100%) create mode 100644 test/assets/comments/JSON28_result.hjson create mode 100644 test/assets/comments/strings4_result.hjson create mode 100644 test/assets/comments/strings5_result.hjson create mode 100644 test/assets/comments2/JSON28_result.hjson create mode 100644 test/assets/comments2/strings4_result.hjson create mode 100644 test/assets/comments2/strings5_result.hjson create mode 100644 test/assets/failStr9a_test.hjson create mode 100644 test/assets/sorted/JSON28_result.hjson create mode 100644 test/assets/sorted/JSON28_result.json create mode 100644 test/assets/sorted/strings4_result.hjson create mode 100644 test/assets/sorted/strings4_result.json create mode 100644 test/assets/sorted/strings5_result.hjson create mode 100644 test/assets/sorted/strings5_result.json create mode 100644 test/assets/strings4_result.hjson create mode 100644 test/assets/strings4_result.json create mode 100644 test/assets/strings4_test.hjson create mode 100644 test/assets/strings5_result.hjson create mode 100644 test/assets/strings5_result.json create mode 100644 test/assets/strings5_test.hjson 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..c5973cb --- /dev/null +++ b/test/assets/comments/strings5_result.hjson @@ -0,0 +1,4 @@ +{ + # escaped \n + 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..c5973cb --- /dev/null +++ b/test/assets/comments2/strings5_result.hjson @@ -0,0 +1,4 @@ +{ + # escaped \n + key: Look, Mom! No \n's! +} 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/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..e575663 --- /dev/null +++ b/test/assets/strings5_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/testlist.txt b/test/assets/testlist.txt index cff5e4d..74459f4 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,9 @@ failStr6c_test.hjson failStr6d_test.hjson failStr7a_test.hjson failStr8a_test.hjson +failStr9a_test.hjson int64_test.hjson +JSON28_test.json kan_test.hjson keys_test.hjson mltabs_test.json @@ -84,6 +85,8 @@ root_test.hjson stringify1_test.hjson strings2_test.hjson strings3_test.hjson +strings4_test.hjson +strings5_test.hjson strings_test.hjson trail_test.hjson windowseol_test.hjson From cdf428d07c37e616cb2cd00eff0916e877d183af Mon Sep 17 00:00:00 2001 From: trobro Date: Sat, 1 May 2021 12:57:16 +0200 Subject: [PATCH 3/5] more tests --- test/assets/comments/strings6_result.hjson | 8 ++++++++ test/assets/comments2/strings6_result.hjson | 8 ++++++++ test/assets/failStr10a_test.hjson | 5 +++++ test/assets/sorted/strings6_result.hjson | 7 +++++++ test/assets/sorted/strings6_result.json | 3 +++ test/assets/strings6_result.hjson | 7 +++++++ test/assets/strings6_result.json | 3 +++ test/assets/strings6_test.hjson | 8 ++++++++ test/assets/testlist.txt | 2 ++ 9 files changed, 51 insertions(+) create mode 100644 test/assets/comments/strings6_result.hjson create mode 100644 test/assets/comments2/strings6_result.hjson create mode 100644 test/assets/failStr10a_test.hjson create mode 100644 test/assets/sorted/strings6_result.hjson create mode 100644 test/assets/sorted/strings6_result.json create mode 100644 test/assets/strings6_result.hjson create mode 100644 test/assets/strings6_result.json create mode 100644 test/assets/strings6_test.hjson 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/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/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/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 74459f4..b61369c 100644 --- a/test/assets/testlist.txt +++ b/test/assets/testlist.txt @@ -69,6 +69,7 @@ failStr6d_test.hjson failStr7a_test.hjson failStr8a_test.hjson failStr9a_test.hjson +failStr10a_test.hjson int64_test.hjson JSON28_test.json kan_test.hjson @@ -87,6 +88,7 @@ strings2_test.hjson strings3_test.hjson strings4_test.hjson strings5_test.hjson +strings6_test.hjson strings_test.hjson trail_test.hjson windowseol_test.hjson From be394684d1742219ce4be864aabb43a177c8377e Mon Sep 17 00:00:00 2001 From: trobro Date: Sat, 1 May 2021 13:00:43 +0200 Subject: [PATCH 4/5] fix test comment --- test/assets/strings5_test.hjson | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/assets/strings5_test.hjson b/test/assets/strings5_test.hjson index e575663..99fcd98 100644 --- a/test/assets/strings5_test.hjson +++ b/test/assets/strings5_test.hjson @@ -1,5 +1,5 @@ { - # escaped \n + # escaped \r\n key: "Look, Mom! \ No \\n's!" } \ No newline at end of file From 77f0ff5b8dd4a50153da5574519c6a97793f1f31 Mon Sep 17 00:00:00 2001 From: trobro Date: Sat, 1 May 2021 13:05:25 +0200 Subject: [PATCH 5/5] fix tests --- test/assets/comments/strings5_result.hjson | 2 +- test/assets/comments2/strings5_result.hjson | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/assets/comments/strings5_result.hjson b/test/assets/comments/strings5_result.hjson index c5973cb..15f12ac 100644 --- a/test/assets/comments/strings5_result.hjson +++ b/test/assets/comments/strings5_result.hjson @@ -1,4 +1,4 @@ { - # escaped \n + # escaped \r\n key: Look, Mom! No \n's! } diff --git a/test/assets/comments2/strings5_result.hjson b/test/assets/comments2/strings5_result.hjson index c5973cb..15f12ac 100644 --- a/test/assets/comments2/strings5_result.hjson +++ b/test/assets/comments2/strings5_result.hjson @@ -1,4 +1,4 @@ { - # escaped \n + # escaped \r\n key: Look, Mom! No \n's! }