Skip to content

Commit

Permalink
Fixes #15 - Invalid parsing of certain characters with \uNNNN
Browse files Browse the repository at this point in the history
  • Loading branch information
aw committed Mar 29, 2018
1 parent 7cc6eac commit 09ce752
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 8 additions & 1 deletion json.l
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@
(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
(while Value
(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)) ]
Expand Down
2 changes: 1 addition & 1 deletion module.l
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
15 changes: 14 additions & 1 deletion test/test_regressions.l
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) ]

0 comments on commit 09ce752

Please sign in to comment.