Do not consider an empty string to be valid JSON. Add some additional

JSON test cases.

FossilOrigin-Name: fd19ff029f128f478f69910352a6f8b84262ce1d
This commit is contained in:
drh 2015-08-29 16:02:37 +00:00
parent a771402e55
commit d1f0068d19
4 changed files with 60 additions and 10 deletions

View File

@ -690,7 +690,7 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
j++;
c = pParse->zJson[j+1];
}
if( c<'0' || c>'0' ) return -1;
if( c<'0' || c>'9' ) return -1;
continue;
}
break;
@ -730,7 +730,7 @@ static int jsonParse(
while( isspace(zJson[i]) ) i++;
if( zJson[i] ) i = -1;
}
if( i<0 ){
if( i<=0 ){
if( pCtx!=0 ){
if( pParse->oom ){
sqlite3_result_error_nomem(pCtx);

View File

@ -1,5 +1,5 @@
C Change\sthe\sjson1.c\smodule\sso\sthat\sit\sthrows\san\serror\sif\sany\sof\sthe\nJSON\sselector\spaths\sare\smalformed.
D 2015-08-29T00:54:49.924
C Do\snot\sconsider\san\sempty\sstring\sto\sbe\svalid\sJSON.\s\sAdd\ssome\sadditional\nJSON\stest\scases.
D 2015-08-29T16:02:37.845
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in e2218eb228374422969de7b1680eda6864affcef
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -192,7 +192,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2
F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f
F ext/misc/fuzzer.c 4c84635c71c26cfa7c2e5848cf49fe2d2cfcd767
F ext/misc/ieee754.c b0362167289170627659e84173f5d2e8fee8566e
F ext/misc/json1.c 063bf62fd44a06aa06fd22854fff09679cbb855f
F ext/misc/json1.c 232a3125fc468e9075f569b1b543b797fd4e0f81
F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342
F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63
F ext/misc/regexp.c af92cdaa5058fcec1451e49becc7ba44dba023dc
@ -810,7 +810,7 @@ F test/journal3.test ff8af941f9e06161d3db1b46bb9f965ff0e7f307
F test/jrnlmode.test 7864d59cf7f6e552b9b99ba0f38acd167edc10fa
F test/jrnlmode2.test 81610545a4e6ed239ea8fa661891893385e23a1d
F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa
F test/json101.test 5dfb181790c123123c8e7981d4d3c941b6cc8af4
F test/json101.test ef8fb3ac6a59b9a435c9fec7a4eb6413ecf76531
F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff
F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63
F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200
@ -1380,7 +1380,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P dc9ce7b18cbe23d065317757234ef9fb8792da7a
R 7515083280f6e706dffbefc132c1a59a
P 3aa0855fd463076fc3277f1d9fe00d2f30e6b449
R 3daa1648ff31e492e4e517b1729e3cd5
U drh
Z f18bb212545a9a98b8ef3bc5262369aa
Z 4768dfaa3613e1e500aa484aea396edc

View File

@ -1 +1 @@
3aa0855fd463076fc3277f1d9fe00d2f30e6b449
fd19ff029f128f478f69910352a6f8b84262ce1d

View File

@ -63,4 +63,54 @@ do_execsql_test json1-3.4 {
SELECT json_type(json_set('{"a":1,"b":2}','$$.b','{"x":3,"y":4}'),'$.b');
} {object}
# Per rfc7159, any JSON value is allowed at the top level, and whitespace
# is permitting before and/or after that value.
#
do_execsql_test json1-4.1 {
CREATE TABLE j1(x);
INSERT INTO j1(x)
VALUES('true'),('false'),('null'),('123'),('-234'),('34.5e+6'),
('""'),('"\""'),('"\\"'),('"abcdefghijlmnopqrstuvwxyz"'),
('[]'),('{}'),('[true,false,null,123,-234,34.5e+6,{},[]]'),
('{"a":true,"b":{"c":false}}');
SELECT * FROM j1 WHERE NOT json_valid(x);
} {}
do_execsql_test json1-4.2 {
SELECT * FROM j1 WHERE NOT json_valid(char(0x20,0x09,0x0a,0x0d)||x);
} {}
do_execsql_test json1-4.3 {
SELECT * FROM j1 WHERE NOT json_valid(x||char(0x20,0x09,0x0a,0x0d));
} {}
# But an empty string, or a string of pure whitespace is not valid JSON.
#
do_execsql_test json1-4.4 {
SELECT json_valid(''), json_valid(char(0x20,0x09,0x0a,0x0d));
} {0 0}
# json_remove() and similar functions with no edit operations return their
# input unchanged.
#
do_execsql_test json1-4.5 {
SELECT x FROM j1 WHERE json_remove(x)<>x;
} {}
do_execsql_test json1-4.6 {
SELECT x FROM j1 WHERE json_replace(x)<>x;
} {}
do_execsql_test json1-4.7 {
SELECT x FROM j1 WHERE json_set(x)<>x;
} {}
do_execsql_test json1-4.8 {
SELECT x FROM j1 WHERE json_insert(x)<>x;
} {}
# json_extract(JSON,'$') will return objects and arrays without change.
#
do_execsql_test json-4.10 {
SELECT count(*) FROM j1 WHERE json_type(x) IN ('object','array');
SELECT x FROM j1
WHERE json_extract(x,'$')<>x
AND json_type(x) IN ('object','array');
} {4}
finish_test