Skip to content

Commit 82efc99

Browse files
committed
FIX: don't fail when decoding "+1" key from JSON data
1 parent 061773c commit 82efc99

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/mezz/codec-json.reb

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Rebol [
33
Type: module
44
Options: [delay]
55
Exports: [to-json load-json]
6-
Version: 0.1.0
6+
Version: 0.1.1
77
Title: "JSON codec"
88
Purpose: "Convert Rebol value into JSON format and back."
99
File: https://raw.githubusercontent.com/Oldes/Rebol3/master/src/mezz/codec-json.reb
@@ -27,6 +27,7 @@ Rebol [
2727
0.0.3 31-Aug-2018 "Gabriele" "Converted to non-recursive version"
2828
0.0.4 9-Oct-2018 "Gabriele" "Back to an easier to read recursive version"
2929
0.1.0 13-Feb-2020 "Oldes" "Ported Red's version back to Rebol"
30+
0.1.1 22-Dec-2021 "Oldes" "Handle '+1' and/or '-1' JSON keys"
3031
]
3132

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

235236
property-list: [property any [sep property]]
236-
property: [json-name (emit either parse _str [word-1st any word-char] [to word! _str] [_str]) json-value]
237+
property: [
238+
json-name (
239+
emit either parse _str [
240+
and [word-1st any word-char]
241+
not [#"+" | #"-"] some digit end ; do not try to convert +1 or -1 to words
242+
] [to word! _str] [_str]
243+
)
244+
json-value
245+
]
237246
json-name: [ws* string-literal ws* #":"]
238247

239248
;-----------------------------------------------------------

src/tests/units/codecs-test.r3

+2
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ if find codecs 'JSON [
399399
data: #(a: 1 b: #(c: 2.0) d: "^/^-")
400400
str: encode 'JSON data
401401
--assert data = decode 'JSON str
402+
; Github is using "+1" and "-1" keys in the `reactions` data now
403+
--assert ["+1" 1] = to block! decode 'JSON {{"+1": 1}}
402404
===end-group===
403405
]
404406

0 commit comments

Comments
 (0)