Skip to content

Commit

Permalink
FIX: don't fail when decoding "+1" key from JSON data
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Dec 22, 2021
1 parent 061773c commit 82efc99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/mezz/codec-json.reb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Rebol [
Type: module
Options: [delay]
Exports: [to-json load-json]
Version: 0.1.0
Version: 0.1.1
Title: "JSON codec"
Purpose: "Convert Rebol value into JSON format and back."
File: https://raw.githubusercontent.com/Oldes/Rebol3/master/src/mezz/codec-json.reb
Expand All @@ -27,6 +27,7 @@ Rebol [
0.0.3 31-Aug-2018 "Gabriele" "Converted to non-recursive version"
0.0.4 9-Oct-2018 "Gabriele" "Back to an easier to read recursive version"
0.1.0 13-Feb-2020 "Oldes" "Ported Red's version back to Rebol"
0.1.1 22-Dec-2021 "Oldes" "Handle '+1' and/or '-1' JSON keys"
]

Rights: "Copyright (C) 2019 Red Foundation. All rights reserved."
Expand Down Expand Up @@ -233,7 +234,15 @@ json-object: [
]

property-list: [property any [sep property]]
property: [json-name (emit either parse _str [word-1st any word-char] [to word! _str] [_str]) json-value]
property: [
json-name (
emit either parse _str [
and [word-1st any word-char]
not [#"+" | #"-"] some digit end ; do not try to convert +1 or -1 to words
] [to word! _str] [_str]
)
json-value
]
json-name: [ws* string-literal ws* #":"]

;-----------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/tests/units/codecs-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ if find codecs 'JSON [
data: #(a: 1 b: #(c: 2.0) d: "^/^-")
str: encode 'JSON data
--assert data = decode 'JSON str
; Github is using "+1" and "-1" keys in the `reactions` data now
--assert ["+1" 1] = to block! decode 'JSON {{"+1": 1}}
===end-group===
]

Expand Down

0 comments on commit 82efc99

Please sign in to comment.