json.reader: fix segfault when parsing non-JSON documents.
parent
922cbebf8a
commit
663fba1d7d
|
@ -1,5 +1,5 @@
|
|||
USING: hashtables io.streams.string json json.reader kernel
|
||||
literals math strings tools.test ;
|
||||
USING: hashtables io.streams.string json json.reader
|
||||
json.reader.private kernel literals math strings tools.test ;
|
||||
IN: json.reader.tests
|
||||
|
||||
{ f } [ "false" json> ] unit-test
|
||||
|
@ -76,3 +76,6 @@ ${ { 0xabcd } >string } [ " \"\\uaBCd\" " json> ] unit-test
|
|||
{ 1/0. } [ "Infinity" json> ] unit-test
|
||||
{ -1/0. } [ "-Infinity" json> ] unit-test
|
||||
{ t } [ "NaN" json> fp-nan? ] unit-test
|
||||
|
||||
[ "<!doctype html>\n<html>\n<head>\n " json> ]
|
||||
[ not-a-json-number? ] must-fail-with
|
||||
|
|
|
@ -9,14 +9,18 @@ IN: json.reader
|
|||
|
||||
<PRIVATE
|
||||
|
||||
ERROR: not-a-json-number string ;
|
||||
|
||||
: json-number ( char stream -- num char )
|
||||
[ 1string ] [ "\s\t\r\n,:}]" swap stream-read-until ] bi*
|
||||
[ append {
|
||||
[
|
||||
append {
|
||||
{ "Infinity" [ 1/0. ] }
|
||||
{ "-Infinity" [ -1/0. ] }
|
||||
{ "NaN" [ 0/0. ] }
|
||||
[ string>number ]
|
||||
} case ] dip ;
|
||||
[ dup string>number [ nip ] [ not-a-json-number ] if* ]
|
||||
} case
|
||||
] dip ;
|
||||
|
||||
: json-expect ( token stream -- )
|
||||
[ dup length ] [ stream-read ] bi* = [ json-error ] unless ; inline
|
||||
|
|
Loading…
Reference in New Issue