]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix json_tree() so that it is able to deal with the JNODE_RAW labels of
authordrh <>
Fri, 28 Apr 2023 11:02:01 +0000 (11:02 +0000)
committerdrh <>
Fri, 28 Apr 2023 11:02:01 +0000 (11:02 +0000)
a JSON5 object.

FossilOrigin-Name: f56528d413d8e622f7c4f18b2f9f2e620bfb441c020461299b35a90072ee6c13

manifest
manifest.uuid
src/json.c
test/json502.test [new file with mode: 0644]

index b8b8e777ef741825ca63532245dae2a3ac996c80..90577f373d3589df48fa5f75441ebcd074c9d12d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\sall\sthe\slatest\strunk\sfixes\sand\senhancements\sinto\sthe\sjson5\sbranch.
-D 2023-04-28T10:23:01.697
+C Fix\sjson_tree()\sso\sthat\sit\sis\sable\sto\sdeal\swith\sthe\sJNODE_RAW\slabels\sof\na\sJSON5\sobject.
+D 2023-04-28T11:02:01.468
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -593,7 +593,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 76c7d11f7a5f29eaf3180c6ffcdf7fa808e931f519295d0725a736be8956a5cd
+F src/json.c 7d03a1185d7aee74f53a3f2381355ff4b71d955f287d29d30c0b0979afc96b67
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c be5af440f3192c58681b5d43167dbca3ccbfce394d89faa22378a14264781136
 F src/main.c 09bc5191f75dc48fc4dfddda143cb864c0c3dbc3297eb9a9c8e01fea58ff847d
@@ -1260,6 +1260,7 @@ F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a888011
 F test/json104.test a502dc01853aada95d721b3b275afbe2dc18fffdac1fea6e96fb20c13586bbb5
 F test/json105.test 11670a4387f4308ae0318cadcbd6a918ea7edcd19fbafde020720a073952675d
 F test/json501.test 43614faefc9ac708e29d55cdc290b5cea336c151030196885708ea3d132fce63
+F test/json502.test 66d150cc098674b8bf4354526a8dd411b926f43ca892306bcb3b6d3f93fef7be
 F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff
 F test/kvtest.c feb4358fb022da8ebd098c45811f2f6507688bb6c43aa72b3e840df19026317b
 F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63
@@ -2065,8 +2066,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 bc84a82e4ddc1b71025c56c49e62a44f0b12fa87a6417ad61967d9d3121a0d4e 91fee79a01971259b21478e60a069a711a00efc79ddfececa6224a152cd8d09a
-R 454da0ecccffebadc86f13fb2a470b64
+P b5ca15cfc19380cf870b70be6a86e70f2026cc3d6d89005b45891d58c4f11c2d
+R fca31e8533435392332b7b8d5d313d4f
 U drh
-Z dbd4148e71a7855c43311d70f48a2c21
+Z 70e5d0234b5092ca91c1a96a87fa5d9d
 # Remove this line to create a well-formed Fossil manifest.
index eb3f235ab79d8283acb1e73dc8aacb9e92d55608..3b090148dc16780dcfa1052c2d28f73bf74bf4be 100644 (file)
@@ -1 +1 @@
-b5ca15cfc19380cf870b70be6a86e70f2026cc3d6d89005b45891d58c4f11c2d
\ No newline at end of file
+f56528d413d8e622f7c4f18b2f9f2e620bfb441c020461299b35a90072ee6c13
\ No newline at end of file
index 6bac63ec518bba680128b1e45cc5b817e0d8787d..1152d9f916c0224c1eb0e175a8c4c02fe70090d0 100644 (file)
@@ -726,17 +726,11 @@ static void jsonReturn(
       break;
     }
     case JSON_STRING: {
-#if 0 /* Never happens because JNODE_RAW is only set by json_set(),
-      ** json_insert() and json_replace() and those routines do not
-      ** call jsonReturn() */
       if( pNode->jnFlags & JNODE_RAW ){
         assert( pNode->eU==1 );
         sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n,
                             SQLITE_TRANSIENT);
-      }else 
-#endif
-      assert( (pNode->jnFlags & JNODE_RAW)==0 );
-      if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
+      }else if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
         /* JSON formatted without any backslash-escapes */
         assert( pNode->eU==1 );
         sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2,
@@ -2872,14 +2866,16 @@ static void jsonAppendObjectPathElement(
   assert( pNode->eU==1 );
   z = pNode->u.zJContent;
   nn = pNode->n;
-  assert( nn>=2 );
-  assert( z[0]=='"' );
-  assert( z[nn-1]=='"' );
-  if( nn>2 && sqlite3Isalpha(z[1]) ){
-    for(jj=2; jj<nn-1 && sqlite3Isalnum(z[jj]); jj++){}
-    if( jj==nn-1 ){
-      z++;
-      nn -= 2;
+  if( (pNode->jnFlags & JNODE_RAW)==0 ){
+    assert( nn>=2 );
+    assert( z[0]=='"' );
+    assert( z[nn-1]=='"' );
+    if( nn>2 && sqlite3Isalpha(z[1]) ){
+      for(jj=2; jj<nn-1 && sqlite3Isalnum(z[jj]); jj++){}
+      if( jj==nn-1 ){
+        z++;
+        nn -= 2;
+      }
     }
   }
   jsonPrintf(nn+2, pStr, ".%.*s", nn, z);
diff --git a/test/json502.test b/test/json502.test
new file mode 100644 (file)
index 0000000..b5e5703
--- /dev/null
@@ -0,0 +1,25 @@
+# 2023-04-28
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements tests for the JSON5 enhancements to the
+# JSON SQL functions extension to the SQLite library.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix json502
+
+do_execsql_test 1.1 {
+  CREATE TABLE t1(x JSON);
+  INSERT INTO t1(x) VALUES('{a:{b:{c:"hello",},},}');
+  SELECT fullkey FROM t1, json_tree(x);
+} {{$} {$.a} {$.a.b} {$.a.b.c}}
+
+finish_test