Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Do not consider an empty string to be valid JSON. Add some additional JSON test cases. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
fd19ff029f128f478f69910352a6f8b8 |
User & Date: | drh 2015-08-29 16:02:37.845 |
Context
2015-08-29
| ||
17:22 | Fix the build with -DSQLITE_OMIT_VIRTUALTABLE. (check-in: 752918def7 user: drh tags: trunk) | |
16:02 | Do not consider an empty string to be valid JSON. Add some additional JSON test cases. (check-in: fd19ff029f user: drh tags: trunk) | |
00:54 | Change the json1.c module so that it throws an error if any of the JSON selector paths are malformed. (check-in: 3aa0855fd4 user: drh tags: trunk) | |
Changes
Changes to ext/misc/json1.c.
︙ | ︙ | |||
686 687 688 689 690 691 692 | if( seenE ) return -1; seenDP = seenE = 1; c = pParse->zJson[j+1]; if( c=='+' || c=='-' ){ j++; c = pParse->zJson[j+1]; } | | | 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 | if( seenE ) return -1; seenDP = seenE = 1; c = pParse->zJson[j+1]; if( c=='+' || c=='-' ){ j++; c = pParse->zJson[j+1]; } if( c<'0' || c>'9' ) return -1; continue; } break; } if( pParse->zJson[j-1]<'0' ) return -1; jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT, j - i, &pParse->zJson[i]); |
︙ | ︙ | |||
726 727 728 729 730 731 732 | pParse->zJson = zJson; i = jsonParseValue(pParse, 0); if( pParse->oom ) i = -1; if( i>0 ){ while( isspace(zJson[i]) ) i++; if( zJson[i] ) i = -1; } | | | 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | pParse->zJson = zJson; i = jsonParseValue(pParse, 0); if( pParse->oom ) i = -1; if( i>0 ){ while( isspace(zJson[i]) ) i++; if( zJson[i] ) i = -1; } if( i<=0 ){ if( pCtx!=0 ){ if( pParse->oom ){ sqlite3_result_error_nomem(pCtx); }else{ sqlite3_result_error(pCtx, "malformed JSON", -1); } } |
︙ | ︙ |
Changes to test/json101.test.
︙ | ︙ | |||
58 59 60 61 62 63 64 65 66 | } {{{"a":[3,4,5],"b":2}}} do_execsql_test json1-3.3 { SELECT json_type(json_set('{"a":1,"b":2}','$.b','{"x":3,"y":4}'),'$.b'); } {text} do_execsql_test json1-3.4 { SELECT json_type(json_set('{"a":1,"b":2}','$$.b','{"x":3,"y":4}'),'$.b'); } {object} finish_test | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | } {{{"a":[3,4,5],"b":2}}} do_execsql_test json1-3.3 { SELECT json_type(json_set('{"a":1,"b":2}','$.b','{"x":3,"y":4}'),'$.b'); } {text} 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 |