diff --git a/assets/JSON28_result.hjson b/assets/JSON28_result.hjson new file mode 100644 index 0000000..0491756 --- /dev/null +++ b/assets/JSON28_result.hjson @@ -0,0 +1,3 @@ +[ + linebreak +] \ No newline at end of file diff --git a/assets/JSON28_result.json b/assets/JSON28_result.json new file mode 100644 index 0000000..120852d --- /dev/null +++ b/assets/JSON28_result.json @@ -0,0 +1,3 @@ +[ + "linebreak" +] \ No newline at end of file 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/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/JSON28_result.hjson b/assets/sorted/JSON28_result.hjson new file mode 100644 index 0000000..0491756 --- /dev/null +++ b/assets/sorted/JSON28_result.hjson @@ -0,0 +1,3 @@ +[ + linebreak +] \ No newline at end of file diff --git a/assets/sorted/JSON28_result.json b/assets/sorted/JSON28_result.json new file mode 100644 index 0000000..120852d --- /dev/null +++ b/assets/sorted/JSON28_result.json @@ -0,0 +1,3 @@ +[ + "linebreak" +] \ 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..6462ce5 --- /dev/null +++ b/assets/sorted/strings4_result.hjson @@ -0,0 +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 new file mode 100644 index 0000000..d21df3d --- /dev/null +++ b/assets/sorted/strings4_result.json @@ -0,0 +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 new file mode 100644 index 0000000..6462ce5 --- /dev/null +++ b/assets/sorted/strings5_result.hjson @@ -0,0 +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 new file mode 100644 index 0000000..d21df3d --- /dev/null +++ b/assets/sorted/strings5_result.json @@ -0,0 +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 new file mode 100644 index 0000000..78fda29 --- /dev/null +++ b/assets/sorted/strings6_result.hjson @@ -0,0 +1,7 @@ +{ + key: + ''' + 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 new file mode 100644 index 0000000..1f1294c --- /dev/null +++ b/assets/sorted/strings6_result.json @@ -0,0 +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 new file mode 100644 index 0000000..6462ce5 --- /dev/null +++ b/assets/strings4_result.hjson @@ -0,0 +1,3 @@ +{ + key: Look, Mom! No \n's! +} \ No newline at end of file diff --git a/assets/strings4_result.json b/assets/strings4_result.json new file mode 100644 index 0000000..d21df3d --- /dev/null +++ b/assets/strings4_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! No \\n's!" +} \ No newline at end of file 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..6462ce5 --- /dev/null +++ b/assets/strings5_result.hjson @@ -0,0 +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 new file mode 100644 index 0000000..d21df3d --- /dev/null +++ b/assets/strings5_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! No \\n's!" +} \ No newline at end of file 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..78fda29 --- /dev/null +++ b/assets/strings6_result.hjson @@ -0,0 +1,7 @@ +{ + key: + ''' + Look, Mom! \ + No \\n's! + ''' +} \ No newline at end of file diff --git a/assets/strings6_result.json b/assets/strings6_result.json new file mode 100644 index 0000000..1f1294c --- /dev/null +++ b/assets/strings6_result.json @@ -0,0 +1,3 @@ +{ + "key": "Look, Mom! \\\nNo \\\\n's!" +} \ No newline at end of file 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..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 @@ -64,7 +63,10 @@ failStr6c_test.hjson failStr6d_test.hjson failStr7a_test.hjson failStr8a_test.hjson +failStr9a_test.hjson +failStr10a_test.hjson kan_test.hjson +JSON28_test.json keys_test.hjson mltabs_test.json oa_test.hjson @@ -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 diff --git a/decode.go b/decode.go index 701eaa0..c16842c 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 {