From d31fae22c275fbeeb8a9479d1bc34b631e36200b Mon Sep 17 00:00:00 2001 From: trobro Date: Sat, 1 May 2021 13:31:43 +0200 Subject: [PATCH 1/6] allow line continuation --- decode.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/decode.go b/decode.go index 701eaa0..ab0db4d 100644 --- a/decode.go +++ b/decode.go @@ -110,6 +110,11 @@ func (p *hjsonParser) readString(allowML bool) (string, error) { uffff = uffff*16 + hex } res.WriteRune(rune(uffff)) + } else if p.ch == '\n' { + // Escaped line feed is ignored (line continuation is allowed). + } else if p->ch == '\r' && p.peek(0) == '\n' { + // Escaped line feed is ignored (line continuation is allowed). + p.next(); } else if ech, ok := escapee[p.ch]; ok { res.WriteByte(ech) } else { From d5e5ed1fceea2b3f5dfc532a4574e2a757380f0e Mon Sep 17 00:00:00 2001 From: trobro Date: Sat, 1 May 2021 13:31:50 +0200 Subject: [PATCH 2/6] tests --- assets/failStr10a_test.hjson | 5 +++++ assets/failStr9a_test.hjson | 4 ++++ assets/sorted/strings4_result.hjson | 3 +++ assets/sorted/strings4_result.json | 3 +++ assets/sorted/strings5_result.hjson | 3 +++ assets/sorted/strings5_result.json | 3 +++ assets/sorted/strings6_result.hjson | 7 +++++++ assets/sorted/strings6_result.json | 3 +++ assets/strings4_result.hjson | 3 +++ assets/strings4_result.json | 3 +++ assets/strings4_test.hjson | 5 +++++ assets/strings5_result.hjson | 3 +++ assets/strings5_result.json | 3 +++ assets/strings5_test.hjson | 5 +++++ assets/strings6_result.hjson | 7 +++++++ assets/strings6_result.json | 3 +++ assets/strings6_test.hjson | 8 ++++++++ assets/testlist.txt | 5 +++++ 18 files changed, 76 insertions(+) create mode 100644 assets/failStr10a_test.hjson create mode 100644 assets/failStr9a_test.hjson create mode 100644 assets/sorted/strings4_result.hjson create mode 100644 assets/sorted/strings4_result.json create mode 100644 assets/sorted/strings5_result.hjson create mode 100644 assets/sorted/strings5_result.json create mode 100644 assets/sorted/strings6_result.hjson create mode 100644 assets/sorted/strings6_result.json create mode 100644 assets/strings4_result.hjson create mode 100644 assets/strings4_result.json create mode 100644 assets/strings4_test.hjson create mode 100644 assets/strings5_result.hjson create mode 100644 assets/strings5_result.json create mode 100644 assets/strings5_test.hjson create mode 100644 assets/strings6_result.hjson create mode 100644 assets/strings6_result.json create mode 100644 assets/strings6_test.hjson diff --git a/assets/failStr10a_test.hjson b/assets/failStr10a_test.hjson new file mode 100644 index 0000000..5616517 --- /dev/null +++ b/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/assets/failStr9a_test.hjson b/assets/failStr9a_test.hjson new file mode 100644 index 0000000..4eb19c7 --- /dev/null +++ b/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/assets/sorted/strings4_result.hjson b/assets/sorted/strings4_result.hjson new file mode 100644 index 0000000..990a45c --- /dev/null +++ b/assets/sorted/strings4_result.hjson @@ -0,0 +1,3 @@ +{ + key: Look, Mom! No \n's! +} diff --git a/assets/sorted/strings4_result.json b/assets/sorted/strings4_result.json new file mode 100644 index 0000000..db239b0 --- /dev/null +++ b/assets/sorted/strings4_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! No \\n's!" +} diff --git a/assets/sorted/strings5_result.hjson b/assets/sorted/strings5_result.hjson new file mode 100644 index 0000000..990a45c --- /dev/null +++ b/assets/sorted/strings5_result.hjson @@ -0,0 +1,3 @@ +{ + key: Look, Mom! No \n's! +} diff --git a/assets/sorted/strings5_result.json b/assets/sorted/strings5_result.json new file mode 100644 index 0000000..db239b0 --- /dev/null +++ b/assets/sorted/strings5_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! No \\n's!" +} diff --git a/assets/sorted/strings6_result.hjson b/assets/sorted/strings6_result.hjson new file mode 100644 index 0000000..dc9cb66 --- /dev/null +++ b/assets/sorted/strings6_result.hjson @@ -0,0 +1,7 @@ +{ + key: + ''' + Look, Mom! \ + No \\n's! + ''' +} diff --git a/assets/sorted/strings6_result.json b/assets/sorted/strings6_result.json new file mode 100644 index 0000000..db8633f --- /dev/null +++ b/assets/sorted/strings6_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! \\\nNo \\\\n's!" +} diff --git a/assets/strings4_result.hjson b/assets/strings4_result.hjson new file mode 100644 index 0000000..990a45c --- /dev/null +++ b/assets/strings4_result.hjson @@ -0,0 +1,3 @@ +{ + key: Look, Mom! No \n's! +} diff --git a/assets/strings4_result.json b/assets/strings4_result.json new file mode 100644 index 0000000..db239b0 --- /dev/null +++ b/assets/strings4_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! No \\n's!" +} diff --git a/assets/strings4_test.hjson b/assets/strings4_test.hjson new file mode 100644 index 0000000..f1e10aa --- /dev/null +++ b/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/assets/strings5_result.hjson b/assets/strings5_result.hjson new file mode 100644 index 0000000..990a45c --- /dev/null +++ b/assets/strings5_result.hjson @@ -0,0 +1,3 @@ +{ + key: Look, Mom! No \n's! +} diff --git a/assets/strings5_result.json b/assets/strings5_result.json new file mode 100644 index 0000000..db239b0 --- /dev/null +++ b/assets/strings5_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! No \\n's!" +} diff --git a/assets/strings5_test.hjson b/assets/strings5_test.hjson new file mode 100644 index 0000000..99fcd98 --- /dev/null +++ b/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/assets/strings6_result.hjson b/assets/strings6_result.hjson new file mode 100644 index 0000000..dc9cb66 --- /dev/null +++ b/assets/strings6_result.hjson @@ -0,0 +1,7 @@ +{ + key: + ''' + Look, Mom! \ + No \\n's! + ''' +} diff --git a/assets/strings6_result.json b/assets/strings6_result.json new file mode 100644 index 0000000..db8633f --- /dev/null +++ b/assets/strings6_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! \\\nNo \\\\n's!" +} diff --git a/assets/strings6_test.hjson b/assets/strings6_test.hjson new file mode 100644 index 0000000..a8e0f30 --- /dev/null +++ b/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/assets/testlist.txt b/assets/testlist.txt index eae48cf..5428ae3 100644 --- a/assets/testlist.txt +++ b/assets/testlist.txt @@ -64,6 +64,8 @@ failStr6c_test.hjson failStr6d_test.hjson failStr7a_test.hjson failStr8a_test.hjson +failStr9a_test.hjson +failStr10a_test.hjson kan_test.hjson keys_test.hjson mltabs_test.json @@ -76,6 +78,9 @@ passSingle_test.hjson stringify1_test.hjson strings2_test.hjson strings_test.hjson +strings4_test.hjson +strings5_test.hjson +strings6_test.hjson trail_test.hjson stringify/quotes_all_test.hjson stringify/quotes_always_test.hjson From 6bcc34855d45f7c3acb674282689e543c9f478a0 Mon Sep 17 00:00:00 2001 From: trobro Date: Sat, 1 May 2021 13:33:43 +0200 Subject: [PATCH 3/6] fix build (?) --- decode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decode.go b/decode.go index ab0db4d..b64794a 100644 --- a/decode.go +++ b/decode.go @@ -112,7 +112,7 @@ func (p *hjsonParser) readString(allowML bool) (string, error) { res.WriteRune(rune(uffff)) } else if p.ch == '\n' { // Escaped line feed is ignored (line continuation is allowed). - } else if p->ch == '\r' && p.peek(0) == '\n' { + } else if p.ch == '\r' && p.peek(0) == '\n' { // Escaped line feed is ignored (line continuation is allowed). p.next(); } else if ech, ok := escapee[p.ch]; ok { From 762e27f34b21f612d8df6870b06adb2b7d4a6f11 Mon Sep 17 00:00:00 2001 From: trobro Date: Sat, 1 May 2021 13:36:00 +0200 Subject: [PATCH 4/6] JSON28 no longer fails --- assets/JSON28_result.hjson | 3 +++ assets/JSON28_result.json | 3 +++ assets/{failJSON28_test.json => JSON28_test.json} | 0 assets/sorted/JSON28_result.hjson | 3 +++ assets/sorted/JSON28_result.json | 3 +++ assets/testlist.txt | 2 +- 6 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 assets/JSON28_result.hjson create mode 100644 assets/JSON28_result.json rename assets/{failJSON28_test.json => JSON28_test.json} (100%) create mode 100644 assets/sorted/JSON28_result.hjson create mode 100644 assets/sorted/JSON28_result.json diff --git a/assets/JSON28_result.hjson b/assets/JSON28_result.hjson new file mode 100644 index 0000000..f9b2fad --- /dev/null +++ b/assets/JSON28_result.hjson @@ -0,0 +1,3 @@ +[ + linebreak +] diff --git a/assets/JSON28_result.json b/assets/JSON28_result.json new file mode 100644 index 0000000..4d89da5 --- /dev/null +++ b/assets/JSON28_result.json @@ -0,0 +1,3 @@ +[ + "linebreak" +] diff --git a/assets/failJSON28_test.json b/assets/JSON28_test.json similarity index 100% rename from assets/failJSON28_test.json rename to assets/JSON28_test.json diff --git a/assets/sorted/JSON28_result.hjson b/assets/sorted/JSON28_result.hjson new file mode 100644 index 0000000..f9b2fad --- /dev/null +++ b/assets/sorted/JSON28_result.hjson @@ -0,0 +1,3 @@ +[ + linebreak +] diff --git a/assets/sorted/JSON28_result.json b/assets/sorted/JSON28_result.json new file mode 100644 index 0000000..4d89da5 --- /dev/null +++ b/assets/sorted/JSON28_result.json @@ -0,0 +1,3 @@ +[ + "linebreak" +] diff --git a/assets/testlist.txt b/assets/testlist.txt index 5428ae3..3438f3b 100644 --- a/assets/testlist.txt +++ b/assets/testlist.txt @@ -22,7 +22,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 @@ -67,6 +66,7 @@ failStr8a_test.hjson failStr9a_test.hjson failStr10a_test.hjson kan_test.hjson +JSON28_test.json keys_test.hjson mltabs_test.json oa_test.hjson From eaa5d30b8d7e665fbf81dfb318f801b32fd36bfb Mon Sep 17 00:00:00 2001 From: trobro Date: Sat, 1 May 2021 13:38:53 +0200 Subject: [PATCH 5/6] no EOL at EOF --- assets/JSON28_result.hjson | 2 +- assets/JSON28_result.json | 2 +- assets/sorted/JSON28_result.hjson | 2 +- assets/sorted/JSON28_result.json | 2 +- assets/sorted/strings4_result.hjson | 2 +- assets/sorted/strings4_result.json | 2 +- assets/sorted/strings5_result.hjson | 2 +- assets/sorted/strings5_result.json | 2 +- assets/sorted/strings6_result.hjson | 2 +- assets/sorted/strings6_result.json | 2 +- assets/strings4_result.hjson | 2 +- assets/strings5_result.hjson | 2 +- assets/strings5_result.json | 2 +- assets/strings6_result.hjson | 2 +- assets/strings6_result.json | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/assets/JSON28_result.hjson b/assets/JSON28_result.hjson index f9b2fad..0491756 100644 --- a/assets/JSON28_result.hjson +++ b/assets/JSON28_result.hjson @@ -1,3 +1,3 @@ [ linebreak -] +] \ No newline at end of file diff --git a/assets/JSON28_result.json b/assets/JSON28_result.json index 4d89da5..120852d 100644 --- a/assets/JSON28_result.json +++ b/assets/JSON28_result.json @@ -1,3 +1,3 @@ [ "linebreak" -] +] \ No newline at end of file diff --git a/assets/sorted/JSON28_result.hjson b/assets/sorted/JSON28_result.hjson index f9b2fad..0491756 100644 --- a/assets/sorted/JSON28_result.hjson +++ b/assets/sorted/JSON28_result.hjson @@ -1,3 +1,3 @@ [ linebreak -] +] \ No newline at end of file diff --git a/assets/sorted/JSON28_result.json b/assets/sorted/JSON28_result.json index 4d89da5..120852d 100644 --- a/assets/sorted/JSON28_result.json +++ b/assets/sorted/JSON28_result.json @@ -1,3 +1,3 @@ [ "linebreak" -] +] \ No newline at end of file diff --git a/assets/sorted/strings4_result.hjson b/assets/sorted/strings4_result.hjson index 990a45c..6462ce5 100644 --- a/assets/sorted/strings4_result.hjson +++ b/assets/sorted/strings4_result.hjson @@ -1,3 +1,3 @@ { key: Look, Mom! No \n's! -} +} \ No newline at end of file diff --git a/assets/sorted/strings4_result.json b/assets/sorted/strings4_result.json index db239b0..d21df3d 100644 --- a/assets/sorted/strings4_result.json +++ b/assets/sorted/strings4_result.json @@ -1,3 +1,3 @@ { "key": "Look, Mom! No \\n's!" -} +} \ No newline at end of file diff --git a/assets/sorted/strings5_result.hjson b/assets/sorted/strings5_result.hjson index 990a45c..6462ce5 100644 --- a/assets/sorted/strings5_result.hjson +++ b/assets/sorted/strings5_result.hjson @@ -1,3 +1,3 @@ { key: Look, Mom! No \n's! -} +} \ No newline at end of file diff --git a/assets/sorted/strings5_result.json b/assets/sorted/strings5_result.json index db239b0..d21df3d 100644 --- a/assets/sorted/strings5_result.json +++ b/assets/sorted/strings5_result.json @@ -1,3 +1,3 @@ { "key": "Look, Mom! No \\n's!" -} +} \ No newline at end of file diff --git a/assets/sorted/strings6_result.hjson b/assets/sorted/strings6_result.hjson index dc9cb66..78fda29 100644 --- a/assets/sorted/strings6_result.hjson +++ b/assets/sorted/strings6_result.hjson @@ -4,4 +4,4 @@ Look, Mom! \ No \\n's! ''' -} +} \ No newline at end of file diff --git a/assets/sorted/strings6_result.json b/assets/sorted/strings6_result.json index db8633f..1f1294c 100644 --- a/assets/sorted/strings6_result.json +++ b/assets/sorted/strings6_result.json @@ -1,3 +1,3 @@ { "key": "Look, Mom! \\\nNo \\\\n's!" -} +} \ No newline at end of file diff --git a/assets/strings4_result.hjson b/assets/strings4_result.hjson index 990a45c..6462ce5 100644 --- a/assets/strings4_result.hjson +++ b/assets/strings4_result.hjson @@ -1,3 +1,3 @@ { key: Look, Mom! No \n's! -} +} \ No newline at end of file diff --git a/assets/strings5_result.hjson b/assets/strings5_result.hjson index 990a45c..6462ce5 100644 --- a/assets/strings5_result.hjson +++ b/assets/strings5_result.hjson @@ -1,3 +1,3 @@ { key: Look, Mom! No \n's! -} +} \ No newline at end of file diff --git a/assets/strings5_result.json b/assets/strings5_result.json index db239b0..d21df3d 100644 --- a/assets/strings5_result.json +++ b/assets/strings5_result.json @@ -1,3 +1,3 @@ { "key": "Look, Mom! No \\n's!" -} +} \ No newline at end of file diff --git a/assets/strings6_result.hjson b/assets/strings6_result.hjson index dc9cb66..78fda29 100644 --- a/assets/strings6_result.hjson +++ b/assets/strings6_result.hjson @@ -4,4 +4,4 @@ Look, Mom! \ No \\n's! ''' -} +} \ No newline at end of file diff --git a/assets/strings6_result.json b/assets/strings6_result.json index db8633f..1f1294c 100644 --- a/assets/strings6_result.json +++ b/assets/strings6_result.json @@ -1,3 +1,3 @@ { "key": "Look, Mom! \\\nNo \\\\n's!" -} +} \ No newline at end of file From a8bcb6d7d018785ecac78395dfa57c3a81651b30 Mon Sep 17 00:00:00 2001 From: trobro Date: Sat, 1 May 2021 13:42:27 +0200 Subject: [PATCH 6/6] leading space -> tab --- assets/strings4_result.json | 2 +- decode.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/strings4_result.json b/assets/strings4_result.json index db239b0..d21df3d 100644 --- a/assets/strings4_result.json +++ b/assets/strings4_result.json @@ -1,3 +1,3 @@ { "key": "Look, Mom! No \\n's!" -} +} \ No newline at end of file diff --git a/decode.go b/decode.go index b64794a..c16842c 100644 --- a/decode.go +++ b/decode.go @@ -110,11 +110,11 @@ func (p *hjsonParser) readString(allowML bool) (string, error) { uffff = uffff*16 + hex } res.WriteRune(rune(uffff)) - } else if p.ch == '\n' { - // Escaped line feed is ignored (line continuation is allowed). - } else if p.ch == '\r' && p.peek(0) == '\n' { - // Escaped line feed is ignored (line continuation is allowed). - p.next(); + } else if p.ch == '\n' { + // Escaped line feed is ignored (line continuation is allowed). + } else if p.ch == '\r' && p.peek(0) == '\n' { + // Escaped line feed is ignored (line continuation is allowed). + p.next(); } else if ech, ok := escapee[p.ch]; ok { res.WriteByte(ech) } else {