]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Omit the json_valid() function. Change the name of json_error() to
authordrh <>
Sun, 30 Apr 2023 19:34:41 +0000 (19:34 +0000)
committerdrh <>
Sun, 30 Apr 2023 19:34:41 +0000 (19:34 +0000)
json_error_position().  Use "NOT json_error_position(X)" as a substitute
for "json_valid5(X)".

FossilOrigin-Name: 34c4e900a9cc51630eeaf01deef74bf5b18d66e0ab1dc61a2023ac8f837a5197

manifest
manifest.uuid
src/json.c
test/json101.test
test/json102.test
test/json501.test

index ac7fedd268e751fa01b0173722198846c7788151..c7969eb46ee9d20dc2e6fad0d632360d6479dead 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\sall\sthe\slatest\strunk\senhancements\sinto\sthe\sJSON5\sbranch\sto\nfacilitate\stesting\sof\sthe\sJSON5\sbranch.
-D 2023-04-29T18:40:48.921
+C Omit\sthe\sjson_valid()\sfunction.\s\sChange\sthe\sname\sof\sjson_error()\sto\njson_error_position().\s\sUse\s"NOT\sjson_error_position(X)"\sas\sa\ssubstitute\nfor\s"json_valid5(X)".
+D 2023-04-30T19:34:41.159
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -595,7 +595,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
 F src/hwtime.h b638809e083b601b618df877b2e89cb87c2a47a01f4def10be4c4ebb54664ac7
 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
 F src/insert.c a8de1db43335fc4946370a7a7e47d89975ad678ddb15078a150e993ba2fb37d4
-F src/json.c f76772b2d780f9711896e10bb6efa32d839d9c3fef225d3476e6f5b6683a04f3
+F src/json.c d216510dbb7900072e4a0cbb1273a21e0a20db57da405b4397abb236a2f30392
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c be5af440f3192c58681b5d43167dbca3ccbfce394d89faa22378a14264781136
 F src/main.c 09bc5191f75dc48fc4dfddda143cb864c0c3dbc3297eb9a9c8e01fea58ff847d
@@ -1256,12 +1256,12 @@ F test/json/README.md 506af1f54574b524106acb50d1a341ab5ddfa6d83fe25095007892b07e
 F test/json/json-generator.tcl dc0dd0f393800c98658fc4c47eaa6af29d4e17527380cd28656fb261bddc8a3f
 F test/json/json-q1.txt 335a7c8ab291d354f33b7decc9559e99a2823d4142291c4be7aa339a631f3c2d
 F test/json/json-speed-check.sh 8b7babf530faa58bd59d6d362cec8e9036a68c5457ff46f3b1f1511d21af6737 x
-F test/json101.test de9c93169b84ac96fd5836c638a2ae1f00e4afbd4003c6b596692d7f05e1cd69
-F test/json102.test 3bdf097757faefadfd88c5695ba8ab076ca8d8680eb8f33d73d44c07cbbc666d
+F test/json101.test 211d75638782370c07e10a847bd66e501ea1537f39c7da4447bfa055c0f261db
+F test/json102.test 13dc9e7b7f359ecb861e02f9bd7019f7342a63d1c354273b0a8f3904050560a8
 F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe
 F test/json104.test a502dc01853aada95d721b3b275afbe2dc18fffdac1fea6e96fb20c13586bbb5
 F test/json105.test 11670a4387f4308ae0318cadcbd6a918ea7edcd19fbafde020720a073952675d
-F test/json501.test 43614faefc9ac708e29d55cdc290b5cea336c151030196885708ea3d132fce63
+F test/json501.test 9b14d14f26659287277a1f6fcf2a932a0a2351e1aae522586b530498c977ce45
 F test/json502.test 66d150cc098674b8bf4354526a8dd411b926f43ca892306bcb3b6d3f93fef7be
 F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff
 F test/kvtest.c feb4358fb022da8ebd098c45811f2f6507688bb6c43aa72b3e840df19026317b
@@ -2068,8 +2068,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 770b09f7a795956be63a06847059370db8dfc88654878d742b7b826947029962 2e85b0e3dcae0915aa6472a3654c8ac72a6b2083c11747f3f657c79bbdaf530b
-R 81b69133758950851391ffde4b6eeead
+P 30d12edebad9b097cd5f0da355304d1cb2f8b70d7c7dff378fd7ad7c8ebf9279
+R 5a03c0d318d1b5343d158677e6158a89
 U drh
-Z 5f3a6d866b7662144df62f2a5c006f47
+Z 50768d32c83122dec00455a3ce19a1c8
 # Remove this line to create a well-formed Fossil manifest.
index 1007d98b66913f35b211a6f27ae48fab28a0d3e2..fa442e628331790d8e9514692ea65afa3d61535d 100644 (file)
@@ -1 +1 @@
-30d12edebad9b097cd5f0da355304d1cb2f8b70d7c7dff378fd7ad7c8ebf9279
\ No newline at end of file
+34c4e900a9cc51630eeaf01deef74bf5b18d66e0ab1dc61a2023ac8f837a5197
\ No newline at end of file
index a78aa8e614c7ccfab2a225355e2b64e8042e9781..8fa08d24433dabad0df3331bf746ca2df9a9ffce 100644 (file)
@@ -134,7 +134,7 @@ struct JsonParse {
   u16 iDepth;        /* Nesting depth */
   u8 nErr;           /* Number of errors seen */
   u8 oom;            /* Set to true if out of memory */
-  u8 has5;           /* True if input has JSON5 features */
+  u8 hasNonstd;      /* True if input uses non-standard features like JSON5 */
   int nJson;         /* Length of the zJson string in bytes */
   u32 iErr;          /* Error location in zJson[] */
   u32 iHold;         /* Replace cache line with the lowest iHold value */
@@ -1086,7 +1086,7 @@ json_parse_restart:
       if( x<=0 ){
         if( x==(-2) ){
           j = pParse->iErr;
-          if( pParse->nNode!=(u32)iThis+1 ) pParse->has5 = 1;
+          if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1;
           pParse->iDepth--;
           break;
         }
@@ -1095,7 +1095,7 @@ json_parse_restart:
           int k;
           for(k=j+1; sqlite3Isalnum(z[k]) || z[k]=='_' || z[k]=='$'; k++){}
           jsonParseAddNode(pParse, JSON_STRING | (JNODE_RAW<<8), k-j, &z[j]);
-          pParse->has5 = 1;
+          pParse->hasNonstd = 1;
           x = k;
         }else{
           if( x!=-1 ) pParse->iErr = j;
@@ -1179,7 +1179,7 @@ json_parse_restart:
       if( x<=0 ){
         if( x==(-3) ){
           j = pParse->iErr;
-          if( pParse->nNode!=(u32)iThis+1 ) pParse->has5 = 1;
+          if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1;
           break;
         }
         if( x!=(-1) ) pParse->iErr = j;
@@ -1218,7 +1218,7 @@ json_parse_restart:
   case '\'': {
     u8 jnFlags;
     char cDelim;
-    pParse->has5 = 1;
+    pParse->hasNonstd = 1;
     jnFlags = JNODE_JSON5;
     goto parse_string;
   case '"':
@@ -1245,11 +1245,11 @@ json_parse_restart:
                 && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2]))
            || (c=='x' && jsonIs2Hex(&z[j+1])) ){
           jnFlags |= (JNODE_ESCAPE|JNODE_JSON5);
-          pParse->has5 = 1;
+          pParse->hasNonstd = 1;
         }else if( c=='\r' ){
           if( z[j+1]=='\n' ) j++;
           jnFlags |= (JNODE_ESCAPE|JNODE_JSON5);
-          pParse->has5 = 1;
+          pParse->hasNonstd = 1;
         }else{
           pParse->iErr = j;
           return -1;
@@ -1288,12 +1288,12 @@ json_parse_restart:
   }
   case '+': {
     u8 seenDP, seenE, jnFlags;
-    pParse->has5 = 1;
+    pParse->hasNonstd = 1;
     jnFlags = JNODE_JSON5;
     goto parse_number;
   case '.':
     if( sqlite3Isdigit(z[i+1]) ){
-      pParse->has5 = 1;
+      pParse->hasNonstd = 1;
       jnFlags = JNODE_JSON5;
       seenE = 0;
       seenDP = JSON_REAL;
@@ -1326,7 +1326,7 @@ json_parse_restart:
       if( c=='0' ){
         if( (z[i+1]=='x' || z[i+1]=='X') && sqlite3Isxdigit(z[i+2]) ){
           assert( seenDP==JSON_INT );
-          pParse->has5 = 1;
+          pParse->hasNonstd = 1;
           jnFlags |= JNODE_JSON5;
           for(j=i+3; sqlite3Isxdigit(z[j]); j++){}
           goto parse_number_finish;
@@ -1359,7 +1359,7 @@ json_parse_restart:
           }
 #endif
           if( z[i+1]=='.' ){
-            pParse->has5 = 1;
+            pParse->hasNonstd = 1;
             jnFlags |= JNODE_JSON5;
             goto parse_number_2;
           }
@@ -1371,7 +1371,7 @@ json_parse_restart:
             pParse->iErr = i+1;
             return -1;
           }else if( (z[i+2]=='x' || z[i+2]=='X') && sqlite3Isxdigit(z[i+3]) ){
-            pParse->has5 = 1;
+            pParse->hasNonstd = 1;
             jnFlags |= JNODE_JSON5;
             for(j=i+4; sqlite3Isxdigit(z[j]); j++){}
             goto parse_number_finish;
@@ -1394,7 +1394,7 @@ json_parse_restart:
       if( c=='e' || c=='E' ){
         if( z[j-1]<'0' ){
           if( ALWAYS(z[j-1]=='.') && ALWAYS(j-2>=i) && sqlite3Isdigit(z[j-2]) ){
-            pParse->has5 = 1;
+            pParse->hasNonstd = 1;
             jnFlags |= JNODE_JSON5;
           }else{
             pParse->iErr = j;
@@ -1422,7 +1422,7 @@ json_parse_restart:
     }
     if( z[j-1]<'0' ){
       if( ALWAYS(z[j-1]=='.') && ALWAYS(j-2>=i) && sqlite3Isdigit(z[j-2]) ){
-        pParse->has5 = 1;
+        pParse->hasNonstd = 1;
         jnFlags |= JNODE_JSON5;
       }else{
         pParse->iErr = j;
@@ -1436,7 +1436,7 @@ json_parse_restart:
   case 'N': {
     if( strncmp(&z[i],"NaN",3)==0 ){
       jsonParseAddNode(pParse, JSON_NULL, 4, "null");
-      pParse->has5 = 1;
+      pParse->hasNonstd = 1;
       return i+3;
     }
     pParse->iErr = i;
@@ -1445,7 +1445,7 @@ json_parse_restart:
   case 'I': {
     if( strncmp(&z[i],"Infinity",8)==0 ){
       jsonParseAddNode(pParse, JSON_REAL, 7, "9.0e999");
-      pParse->has5 = 1;
+      pParse->hasNonstd = 1;
       return i+8;
     }
     pParse->iErr = i;
@@ -1490,7 +1490,7 @@ json_parse_restart:
     j = json5Whitespace(&z[i]);
     if( j>0 ){
       i += j;
-      pParse->has5 = 1;
+      pParse->hasNonstd = 1;
       goto json_parse_restart;
     }
     pParse->iErr = i;
@@ -1545,7 +1545,7 @@ static int jsonParse(
         jsonParseReset(pParse);
         return 1;
       }
-      pParse->has5 = 1;
+      pParse->hasNonstd = 1;
     }
   }
   if( i<=0 ){
@@ -2571,43 +2571,38 @@ static void jsonValidFunc(
     sqlite3_result_error_nomem(ctx);
     sqlite3_free(p);
   }else{
-    sqlite3_result_int(ctx, p->nErr==0 && p->has5==0);
+    sqlite3_result_int(ctx, p->nErr==0 && p->hasNonstd==0);
     if( p->nErr ) jsonParseFree(p);
   }
 }
 
-
 /*
-** json_valid5(JSON)
+** json_error_position(JSON)
 **
-** Return 1 if JSON is a well-formed JSON5 string.
-** Return 0 otherwise.
-*/
-static void jsonValid5Func(
-  sqlite3_context *ctx,
-  int argc,
-  sqlite3_value **argv
-){
-  JsonParse *p;          /* The parse */
-  UNUSED_PARAMETER(argc);
-  p = jsonParseCached(ctx, argv, 0);
-  if( p==0 || p->oom ){
-    sqlite3_result_error_nomem(ctx);
-    sqlite3_free(p);
-  }else{
-    sqlite3_result_int(ctx, p->nErr==0);
-    if( p->nErr ) jsonParseFree(p);
-  }
-}
-
-
-
-/*
-** json_error(JSON)
+** If the argument is not an interpretable JSON string, then return the 1-based
+** character position at which the parser first recognized that the input
+** was in error.  The left-most character is 1.  If the string is valid
+** JSON, then return 0.
+**
+** Note that json_valid() is only true for strictly conforming canonical JSON.
+** But this routine returns zero if the input contains extension.  Thus:
+**
+** (1) If the input X is strictly conforming canonical JSON:
+**
+**         json_valid(X) returns true
+**         json_error_position(X) returns 0
+**
+** (2) If the input X is JSON but it includes extension (such as JSON5) that
+**     are not part of RFC-8259:
+**
+**         json_valid(X) returns false
+**         json_error_position(X) return 0
+**
+** (3) If the input X cannot be interpreted as JSON even taking extensions
+**     into account:
 **
-** If JSON is not a well-formed JSON5 string, then return the 1-based
-** character offset to the location of the first error in that string.
-** Return 0 otherwise.
+**         json_valid(X) return false
+**         json_error_position(X) returns 1 or more
 */
 static void jsonErrorFunc(
   sqlite3_context *ctx,
@@ -3344,7 +3339,7 @@ void sqlite3RegisterJsonFunctions(void){
     JFUNCTION(json_array,        -1, 0,  jsonArrayFunc),
     JFUNCTION(json_array_length,  1, 0,  jsonArrayLengthFunc),
     JFUNCTION(json_array_length,  2, 0,  jsonArrayLengthFunc),
-    JFUNCTION(json_error,         1, 0,  jsonErrorFunc),
+    JFUNCTION(json_error_position,1, 0,  jsonErrorFunc),
     JFUNCTION(json_extract,      -1, 0,  jsonExtractFunc),
     JFUNCTION(->,                 2, JSON_JSON, jsonExtractFunc),
     JFUNCTION(->>,                2, JSON_SQL, jsonExtractFunc),
@@ -3358,7 +3353,6 @@ void sqlite3RegisterJsonFunctions(void){
     JFUNCTION(json_type,          1, 0,  jsonTypeFunc),
     JFUNCTION(json_type,          2, 0,  jsonTypeFunc),
     JFUNCTION(json_valid,         1, 0,  jsonValidFunc),
-    JFUNCTION(json_valid5,        1, 0,  jsonValid5Func),
 #if SQLITE_DEBUG
     JFUNCTION(json_parse,         1, 0,  jsonParseFunc),
     JFUNCTION(json_test1,         1, 0,  jsonTest1Func),
index 3fc3923da30d2253cdbcbf52c80138289160eaa4..298dc3bdbce8e7a7d06b5847901e8c65df96520e 100644 (file)
@@ -310,8 +310,8 @@ do_execsql_test json-6.1 {
   SELECT json_valid('{"a":55,"b":72,}');
 } {0}
 do_execsql_test json-6.2 {
-  SELECT json_valid5('{"a":55,"b":72,}');
-} {1}
+  SELECT json_error_position('{"a":55,"b":72,}');
+} {0}
 do_execsql_test json-6.3 {
   SELECT json_valid(json('{"a":55,"b":72,}'));
 } {1}
@@ -319,23 +319,23 @@ do_execsql_test json-6.4 {
   SELECT json_valid('{"a":55,"b":72 , }');
 } {0}
 do_execsql_test json-6.5 {
-  SELECT json_valid5('{"a":55,"b":72 , }');
-} {1}
-do_execsql_test json-6.6 {
-  SELECT json_valid5('{"a":55,"b":72,,}');
+  SELECT json_error_position('{"a":55,"b":72 , }');
 } {0}
+do_execsql_test json-6.6 {
+  SELECT json_error_position('{"a":55,"b":72,,}');
+} {16}
 do_execsql_test json-6.7 {
   SELECT json_valid('{"a":55,"b":72}');
 } {1}
 do_execsql_test json-6.8 {
-  SELECT json_valid5('["a",55,"b",72,]');
-} {1}
+  SELECT json_error_position('["a",55,"b",72,]');
+} {0}
 do_execsql_test json-6.9 {
-  SELECT json_valid5('["a",55,"b",72 , ]');
-} {1}
-do_execsql_test json-6.10 {
-  SELECT json_valid5('["a",55,"b",72,,]');
+  SELECT json_error_position('["a",55,"b",72 , ]');
 } {0}
+do_execsql_test json-6.10 {
+  SELECT json_error_position('["a",55,"b",72,,]');
+} {16}
 do_execsql_test json-6.11 {
   SELECT json_valid('["a",55,"b",72]');
 } {1}
index 2594feafa14f1c34e626c9aafd3e687a003dbaad..bfd5e7ed07488a9b19fd43d97619851145b99313 100644 (file)
@@ -319,7 +319,7 @@ foreach {id j x0 x5} {
   1415 {'{"x":+5.5}'} 0 1
 } {
   do_execsql_test json102-$id "
-     SELECT json_valid($j), json_valid5($j);
+     SELECT json_valid($j), NOT json_error_position($j);
   " [list $x0 $x5]
 }
 
index fbf7bfe9db7019718f9d584549e9ff29d3d56ca5..4d6a058936a3ec2d32be99f8286f7e8ed9c36810 100644 (file)
@@ -63,7 +63,7 @@ set testprefix json501
 #    1) Object keys may be an ECMAScript 5.1 IdentifierName.
 do_execsql_test 1.1 {
   WITH c(x) AS (VALUES('{a:5,b:6}'))
-  SELECT x->>'a', json(x), json_valid(x), json_valid5(x) FROM c;
+  SELECT x->>'a', json(x), json_valid(x), NOT json_error_position(x) FROM c;
 } {5 {{"a":5,"b":6}} 0 1}
 do_execsql_test 1.2 {
   SELECT '[7,null,{a:5,b:6},[8,9]]'->>'$[2].b';
@@ -98,7 +98,7 @@ do_catchsql_test 1.11 {
 
 do_execsql_test 2.1 {
   WITH c(x) AS (VALUES('{"a":5, "b":6, }'))
-  SELECT x->>'b', json(x), json_valid(x), json_valid5(x) FROM c;
+  SELECT x->>'b', json(x), json_valid(x), NOT json_error_position(x) FROM c;
 } {6 {{"a":5,"b":6}} 0 1}
 do_execsql_test 2.2 {
   SELECT '{a:5, b:6 , }'->>'b';
@@ -115,7 +115,7 @@ do_catchsql_test 2.4 {
 
 do_execsql_test 3.1 {
   WITH c(x) AS (VALUES('[5, 6,]'))
-  SELECT x->>1, json(x), json_valid(x), json_valid5(x) FROM c;
+  SELECT x->>1, json(x), json_valid(x), NOT json_error_position(x) FROM c;
 } {6 {[5,6]} 0 1}
 do_execsql_test 3.2 {
   SELECT '[5, 6 , ]'->>1;
@@ -132,7 +132,7 @@ do_catchsql_test 3.4 {
 
 do_execsql_test 4.1 {
   WITH c(x) AS (VALUES('{"a": ''abcd''}'))
-  SELECT x->>'a', json(x), json_valid(x), json_valid5(x) FROM c;
+  SELECT x->>'a', json(x), json_valid(x), NOT json_error_position(x) FROM c;
 } {abcd {{"a":"abcd"}} 0 1}
 do_execsql_test 4.2 {
   SELECT '{b: 123, ''a'': ''ab\''cd''}'->>'a';
@@ -143,7 +143,7 @@ do_execsql_test 4.2 {
 
 do_execsql_test 5.1 {
   WITH c(x) AS (VALUES('{a: "abc'||char(0x5c,0x0a)||'xyz"}'))
-  SELECT x->>'a', json(x), json_valid(x), json_valid5(x) FROM c;
+  SELECT x->>'a', json(x), json_valid(x), NOT json_error_position(x) FROM c;
 } {abcxyz {{"a":"abcxyz"}} 0 1}
 do_execsql_test 5.2 {
   SELECT ('{a: "abc'||char(0x5c,0x0d)||'xyz"}')->>'a';