diff --git a/CHANGELOG.md b/CHANGELOG.md index 61fb13a..380b5a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 3.8.0 (2018-03-29) + + * Fix issue #15 - Invalid parsing of certain characters with \uNNNN + * Add regression tests for this issue + ## 3.7.0 (2018-03-21) * Fix issue #13 - Invalid encoding of control characters 0x01-0x1F diff --git a/json.l b/json.l index ee20275..ff96a83 100644 --- a/json.l +++ b/json.l @@ -30,6 +30,13 @@ (json-count-brackets Str) Str ] +[de json-parse-unicode-special (Value) + (case (lowc Value) + ("0022" "\\\"") + ("005c" "\\\\") + ("005e" "\\\^") + (T (char (hex Value) ] + [de json-parse-unicode (Value) (pack (make @@ -37,7 +44,7 @@ (let R (pop 'Value) (cond [(= "\^" R) (link "\\\^") ] # ^ becomes \^ - [(and (= "\\" R) (= "u" (car Value))) (let U (cut 5 'Value) (link (char (hex (pack (tail 4 U) ] # \uNNNN hex + [(and (= "\\" R) (= "u" (car Value))) (let U (cut 5 'Value) (link (json-parse-unicode-special (pack (tail 4 U) ] # \uNNNN hex [(and (= "\\" R) (= "b" (car Value))) (pop 'Value) (link (char (hex "08") ] # \b backspace [(and (= "\\" R) (= "f" (car Value))) (pop 'Value) (link (char (hex "0C") ] # \f formfeed (T (link R)) ] diff --git a/module.l b/module.l index 55cb050..07d5c99 100644 --- a/module.l +++ b/module.l @@ -1,6 +1,6 @@ [de MODULE_INFO ("name" "json") - ("version" "3.7.0") + ("version" "3.8.0") ("summary" "JSON encoder/decoder for PicoLisp") ("source" "https://github.com/aw/picolisp-json.git") ("author" "Alexander Williams") diff --git a/test/test_regressions.l b/test/test_regressions.l index bd61b3a..910aade 100644 --- a/test/test_regressions.l +++ b/test/test_regressions.l @@ -105,6 +105,18 @@ (encode (list (cons "test" (pack "^A^^^_" (char 32))))) "Regression test GH issue #13 - Invalid encoding of control characters 0x01-0x1F (2)" ) ] +}# Invalid parsing of certain characters with \uNNNN - https://github.com/aw/picolisp-json/issues/15 +[de test-gh-issue-15 () + (assert-equal '(("test" . "\"")) + (decode "{\"test\":\"\\u0022\"}") + "Regression test GH issue #15 - Invalid parsing of certain characters with \uNNNN (1)" ) + (assert-equal '(("test" . "\\")) + (decode "{\"test\":\"\\u005c\"}") + "Regression test GH issue #15 - Invalid parsing of certain characters with \uNNNN (2)" ) + (assert-equal '(("test" . "\^")) + (decode "{\"test\":\"\\u005e\"}") + "Regression test GH issue #15 - Invalid parsing of certain characters with \uNNNN (3)" ) ] + [execute '(test-gh-issue-4) '(test-gh-issue-5) @@ -114,4 +126,5 @@ '(test-gh-issue-10) '(test-gh-issue-11) '(test-gh-issue-12) - '(test-gh-issue-13) ] + '(test-gh-issue-13) + '(test-gh-issue-15) ]