]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
JSON string literals may span multiple lines by escaping new line characters.
authordrh <>
Thu, 27 Apr 2023 15:48:58 +0000 (15:48 +0000)
committerdrh <>
Thu, 27 Apr 2023 15:48:58 +0000 (15:48 +0000)
FossilOrigin-Name: 66da4bd4a30c390fa1a7960ce2edaef82e63971ecf33ffb6b906db9f278041c5

manifest
manifest.uuid
src/json.c

index ff21e8d8d77a0bafb8dc82013779152e56645d22..fff4f23d062f83e80bbc3bd8e83ee1a7cc81d9c0 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Allow\sthe\slabels\son\sJSON\sobjects\sto\sbe\sunquoted\sidentifier\snames.
-D 2023-04-27T15:11:26.153
+C JSON\sstring\sliterals\smay\sspan\smultiple\slines\sby\sescaping\snew\sline\scharacters.
+D 2023-04-27T15:48:58.281
 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 22e67e7ae7d1bd46df5616452a7b14587799df6dfff0c47bd09c3926c89ead99
+F src/json.c d0a088f85237afcf78aa9607261a4912ce1a42db3fca907305f78da8be0c51d9
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c be5af440f3192c58681b5d43167dbca3ccbfce394d89faa22378a14264781136
 F src/main.c 09bc5191f75dc48fc4dfddda143cb864c0c3dbc3297eb9a9c8e01fea58ff847d
@@ -2063,8 +2063,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 5a88ba743f55d45b1c0ce0090bb3b396bcf7fcf7b3bcb989aaf30b8bb772599e
-R 7efb5a3476c2275fadcb3d73f88a7a54
+P fb428db3f64f148ab9a3478fdcc8b3733e58102b3c8895a482e2551d974d5661
+R 187d7b6dd1b32f74babea313dab398fc
 U drh
-Z 22784998a1ee89abb38fb8b4e89c3f5d
+Z 182d7f6abcc455723bd9a825ca2f2b58
 # Remove this line to create a well-formed Fossil manifest.
index ec0911a1844daef21a85c4c37dcae965390ca5bf..6a4b1b10bd2a4c80c1ff6aca7e824fd5f6c18477 100644 (file)
@@ -1 +1 @@
-fb428db3f64f148ab9a3478fdcc8b3733e58102b3c8895a482e2551d974d5661
\ No newline at end of file
+66da4bd4a30c390fa1a7960ce2edaef82e63971ecf33ffb6b906db9f278041c5
\ No newline at end of file
index 178267bdd1ccf070618eb1bc15b1d5c8da9c534f..e446830db92846b9caa0ed322440be27b64ae2f5 100644 (file)
@@ -316,7 +316,7 @@ static void jsonAppendNormalizedString(JsonString *p, const char *zIn, u32 N){
       if( N==0 ) break;     
     }
     assert( zIn[0]=='\\' );
-    switch( zIn[1] ){
+    switch( (u8)zIn[1] ){
       case '\'':
         jsonAppendChar(p, '\'');
         break;
@@ -332,6 +332,21 @@ static void jsonAppendNormalizedString(JsonString *p, const char *zIn, u32 N){
       case '0':
         jsonAppendRaw(p, "\\u0000", 6);
         break;
+      case '\r':
+        if( N>=3 && zIn[2]=='\n' ){
+          zIn++;
+          N--;
+        }
+        break;
+      case '\n':
+        break;
+      case 0xe2:
+        assert( N>=4 );
+        assert( 0x80==(u8)zIn[2] );
+        assert( 0xa8==(u8)zIn[3] || 0xa9==(u8)zIn[3] );
+        zIn += 2;
+        N -= 2;
+        break;
       default:
         jsonAppendRaw(p, zIn, 2);
         break;
@@ -742,9 +757,7 @@ static void jsonReturn(
         }
         for(i=1, j=0; i<n-1; i++){
           char c = z[i];
-          if( c!='\\' ){
-            zOut[j++] = c;
-          }else{
+          if( c=='\\' ){
             c = z[++i];
             if( c=='u' ){
               u32 v = jsonHexToInt4(z+i+1);
@@ -776,31 +789,42 @@ static void jsonReturn(
                   zOut[j++] = 0x80 | (v&0x3f);
                 }
               }
+              continue;
+            }else if( c=='b' ){
+              c = '\b';
+            }else if( c=='f' ){
+              c = '\f';
+            }else if( c=='n' ){
+              c = '\n';
+            }else if( c=='r' ){
+              c = '\r';
+            }else if( c=='t' ){
+              c = '\t';
+            }else if( c=='v' ){
+              c = '\v';
+            }else if( c=='\'' ){
+              c = '\'';
+            }else if( c=='"' ){
+              c = '"';
+            }else if( c=='0' ){
+              c = 0;
+            }else if( c=='x' ){
+              c = (jsonHexToInt(z[i+1])<<4) | jsonHexToInt(z[i+2]);
+              i += 2;
+            }else if( c=='\r' && z[i+1]=='\n' ){
+              i++;
+              continue;
+            }else if( 0xe2==(u8)c ){
+              assert( 0x80==(u8)z[i+1] );
+              assert( 0xa8==(u8)z[i+2] || 0xa9==(u8)z[i+2] );
+              i+= 2;
+              continue;
             }else{
-              if( c=='b' ){
-                c = '\b';
-              }else if( c=='f' ){
-                c = '\f';
-              }else if( c=='n' ){
-                c = '\n';
-              }else if( c=='r' ){
-                c = '\r';
-              }else if( c=='t' ){
-                c = '\t';
-              }else if( c=='v' ){
-                c = '\v';
-              }else if( c=='\'' ){
-                c = '\'';
-              }else if( c=='0' ){
-                c = 0;
-              }else if( c=='x' ){
-                c = (jsonHexToInt(z[i+1])<<4) | jsonHexToInt(z[i+2]);
-                i += 2;
-              }
-              zOut[j++] = c;
+              continue;
             }
-          }
-        }
+          } /* end if( c=='\\' ) */
+          zOut[j++] = c;
+        } /* end for() */
         zOut[j] = 0;
         sqlite3_result_text(pCtx, zOut, j, sqlite3_free);
       }
@@ -1202,6 +1226,9 @@ json_parse_restart:
            || (c=='u' && jsonIs4Hex(&z[j+1])) ){
           jnFlags |= JNODE_ESCAPE;
         }else if( c=='\'' || c=='0' || c=='v'
+           || c=='\r' || c=='\n'
+           || (0xe2==(u8)c && 0x80==(u8)z[j+1]
+                && (0xa8==(u8)z[j+2] || 0xa9==(u8)z[j+2]))
            || (c=='x' && jsonIs2Hex(&z[j+1])) ){
           jnFlags |= (JNODE_ESCAPE|JNODE_JSON5);
           pParse->has5 = 1;