json reader: correctly handle empty objects in objects
Attempting to parse { "foo" : {} } previously resulted in an error.
(close-hash) expected to consolidate an object into the values of the
containing object (in the first line of code). While there is none in
the case of the empty hash, the structure of the accumulator looked like
it contained an unconsolidated object, so it folded the values into the
keys and got very confused.
parent
92393c7df7
commit
43a7facd09
|
|
@ -1,4 +1,4 @@
|
||||||
USING: arrays json.reader kernel strings tools.test
|
USING: assocs arrays json.reader kernel strings tools.test
|
||||||
hashtables json ;
|
hashtables json ;
|
||||||
IN: json.reader.tests
|
IN: json.reader.tests
|
||||||
|
|
||||||
|
|
@ -58,3 +58,6 @@ IN: json.reader.tests
|
||||||
{ 0 } [ " 0" json> ] unit-test
|
{ 0 } [ " 0" json> ] unit-test
|
||||||
{ 0 } [ "0 " json> ] unit-test
|
{ 0 } [ "0 " json> ] unit-test
|
||||||
{ 0 } [ " 0 " json> ] unit-test
|
{ 0 } [ " 0 " json> ] unit-test
|
||||||
|
|
||||||
|
! empty objects are allowed as values in objects
|
||||||
|
{ H{ { "foo" H{ } } } } [ "{ \"foo\" : {}}" json> ] unit-test
|
||||||
|
|
|
||||||
|
|
@ -68,12 +68,12 @@ DEFER: j-string
|
||||||
dup pop >array over push ;
|
dup pop >array over push ;
|
||||||
|
|
||||||
: (close-hash) ( accum -- accum' )
|
: (close-hash) ( accum -- accum' )
|
||||||
dup length 3 >= [ v-over-push ] when
|
dup [ length 3 >= ] [ last V{ } = not ] bi@ and [ v-over-push ] when
|
||||||
dup dup [ pop ] dip pop swap
|
dup dup [ pop ] bi@ swap
|
||||||
zip H{ } assoc-clone-like over push ;
|
zip H{ } assoc-clone-like over push ;
|
||||||
|
|
||||||
: scan ( accum char -- accum )
|
: scan ( accum char -- accum )
|
||||||
! 2dup . . ! Great for debug...
|
! 2dup 1string swap . . ! Great for debug...
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
{ CHAR: \" [ j-string over push ] }
|
{ CHAR: \" [ j-string over push ] }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue