]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
The json_valid() function only returns true for pure JSON. JSON5 (or
authordrh <>
Tue, 25 Apr 2023 21:24:20 +0000 (21:24 +0000)
committerdrh <>
Tue, 25 Apr 2023 21:24:20 +0000 (21:24 +0000)
at least that subset of JSON5 that has been so far implemented) is accepted
by all routines, but json_valid() still returns false for JSON5 inputs.
The new json_valid5(X) routine returns true or false if X is or is not valid
JSON5.  All of this is experimental and subject to change.

FossilOrigin-Name: 5d33ab77800765c8b3a13ffcc02ba8a348d71b2b425924560418b517d723494d

manifest
manifest.uuid
src/json.c

index d92e1a5b2bc75c189652c2431fe11bfd711816e1..b5b8818efe4933f7141791d902fc88154db26301 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Allow\strailing\scommas\sin\sobjects\sand\sarrays\sof\sJSON.
-D 2023-04-24T23:14:34.394
+C The\sjson_valid()\sfunction\sonly\sreturns\strue\sfor\spure\sJSON.\s\sJSON5\s(or\nat\sleast\sthat\ssubset\sof\sJSON5\sthat\shas\sbeen\sso\sfar\simplemented)\sis\saccepted\nby\sall\sroutines,\sbut\sjson_valid()\sstill\sreturns\sfalse\sfor\sJSON5\sinputs.\nThe\snew\sjson_valid5(X)\sroutine\sreturns\strue\sor\sfalse\sif\sX\sis\sor\sis\snot\svalid\nJSON5.\s\sAll\sof\sthis\sis\sexperimental\sand\ssubject\sto\schange.
+D 2023-04-25T21:24:20.117
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -592,7 +592,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 ebb5827e6ab6e527c1cafdc857858cc38d822480594ba054a7b26d1493293b4b
+F src/json.c 1d049d073c0197d55e0046877cb87ad7b462419748cf08663d3baf04db676efb
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c be5af440f3192c58681b5d43167dbca3ccbfce394d89faa22378a14264781136
 F src/main.c 09bc5191f75dc48fc4dfddda143cb864c0c3dbc3297eb9a9c8e01fea58ff847d
@@ -2059,11 +2059,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 122431d3a7267ec83768316ab146c0557fb6c0577a4a47ac6ed3d7aa6811ca9a
-R 9daab91f5de799face026ab747c90d1d
-T *branch * json5
-T *sym-json5 *
-T -sym-trunk *
+P 4031b231c223db598b45dbd192b027a99a9b82a981d43c75f723a3fb06720b82
+R 4aa06ba3d655f30dc5fe96279fd3a8e6
 U drh
-Z e1af4267df4cb005f405e96353c52d96
+Z 9b40834215aad90a070495da8b812bef
 # Remove this line to create a well-formed Fossil manifest.
index ef3e218689f8031e8d2be7253afca348a8fcbf61..b9efb7f40f6c5dfd09f5531dac12ba1d4a839f3d 100644 (file)
@@ -1 +1 @@
-4031b231c223db598b45dbd192b027a99a9b82a981d43c75f723a3fb06720b82
\ No newline at end of file
+5d33ab77800765c8b3a13ffcc02ba8a348d71b2b425924560418b517d723494d
\ No newline at end of file
index 4c68608deb4fb67735452f2fc5793e33d10c56ee..b201fdde5c127a8f251bcbee200947166452e8e1 100644 (file)
@@ -130,9 +130,10 @@ struct JsonParse {
   JsonNode *aNode;   /* Array of nodes containing the parse */
   const char *zJson; /* Original JSON string */
   u32 *aUp;          /* Index of parent of each node */
-  u8 oom;            /* Set to true if out of memory */
-  u8 nErr;           /* Number of errors seen */
   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 */
   int nJson;         /* Length of the zJson string in bytes */
   u32 iHold;         /* Replace cache line with the lowest iHold value */
 };
@@ -804,7 +805,10 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
       x = jsonParseValue(pParse, j);
       if( x<0 ){
         pParse->iDepth--;
-        if( x==(-2) ) break;
+        if( x==(-2) ){
+          if( pParse->nNode!=(u32)iThis+1 ) pParse->has5 = 1;
+          break;
+        }
         return -1;
       }
       if( pParse->oom ) return -1;
@@ -838,7 +842,10 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
       x = jsonParseValue(pParse, j);
       pParse->iDepth--;
       if( x<0 ){
-        if( x==(-3) ) break;
+        if( x==(-3) ){
+          if( pParse->nNode!=(u32)iThis+1 ) pParse->has5 = 1;
+          break;
+        }
         return -1;
       }
       j = x;
@@ -1997,6 +2004,16 @@ static void jsonValidFunc(
   sqlite3_context *ctx,
   int argc,
   sqlite3_value **argv
+){
+  JsonParse *p;          /* The parse */
+  UNUSED_PARAMETER(argc);
+  p = jsonParseCached(ctx, argv, 0);
+  sqlite3_result_int(ctx, p!=0 && p->has5==0);
+}
+static void jsonValid5Func(
+  sqlite3_context *ctx,
+  int argc,
+  sqlite3_value **argv
 ){
   JsonParse *p;          /* The parse */
   UNUSED_PARAMETER(argc);
@@ -2725,6 +2742,7 @@ 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),