SQLite

Check-in [84fe95d2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the JSON Path parser so that it will accept zero-length object labels. Forum thread c082aeab43.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 84fe95d2a5b4d232d657e3b8110027a698a9bcd597f205cc535cfa97bc299f21
User & Date: drh 2022-04-04 14:24:14
Original Comment: Fix the JSON Path parser so that it will accept zero-length object labels. [forum/forumpost/c082aeab43|Forum thread c082aeab43].
Context
2022-04-04
15:26
Fix two minor problems in the JSON functions associated with JSON Paths for object labels that require quoting. (check-in: 4a1553b5 user: drh tags: branch-3.38)
15:15
When constructing the JSON Path for the "fullpath" column of the json_tree() and json_each() table-valued functions, be sure to quote object labels where necessary. (check-in: 0fbbe788 user: drh tags: trunk)
14:24
Fix the JSON Path parser so that it will accept zero-length object labels. Forum thread c082aeab43. (check-in: 84fe95d2 user: drh tags: trunk)
11:38
Performance optimization and stronger assert()s in the comparison opcodes. (check-in: e0305e64 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/json.c.
1115
1116
1117
1118
1119
1120
1121

1122
1123
1124
1125
1126
1127
1128
1129

1130
1131
1132
1133
1134
1135
1136
      nKey = i-1;
      if( zPath[i] ){
        i++;
      }else{
        *pzErr = zPath;
        return 0;
      }

    }else{
      zKey = zPath;
      for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
      nKey = i;
    }
    if( nKey==0 ){
      *pzErr = zPath;
      return 0;

    }
    j = 1;
    for(;;){
      while( j<=pRoot->n ){
        if( jsonLabelCompare(pRoot+j, zKey, nKey) ){
          return jsonLookupStep(pParse, iRoot+j+1, &zPath[i], pApnd, pzErr);
        }







>




<
|
|
|
>







1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126

1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
      nKey = i-1;
      if( zPath[i] ){
        i++;
      }else{
        *pzErr = zPath;
        return 0;
      }
      testcase( nKey==0 );
    }else{
      zKey = zPath;
      for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
      nKey = i;

      if( nKey==0 ){
        *pzErr = zPath;
        return 0;
      }
    }
    j = 1;
    for(;;){
      while( j<=pRoot->n ){
        if( jsonLabelCompare(pRoot+j, zKey, nKey) ){
          return jsonLookupStep(pParse, iRoot+j+1, &zPath[i], pApnd, pzErr);
        }
Changes to test/json101.test.
845
846
847
848
849
850
851

















852
853
do_execsql_test json-17.1 {
  DROP TABLE IF EXISTS t1;
  DROP TABLE IF EXISTS t2;
  CREATE TABLE t1(a,b,c);
  CREATE TABLE t2(d);
  SELECT * FROM t1 LEFT JOIN t2 ON (SELECT b FROM json_each ORDER BY 1);
} {}


















finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
do_execsql_test json-17.1 {
  DROP TABLE IF EXISTS t1;
  DROP TABLE IF EXISTS t2;
  CREATE TABLE t1(a,b,c);
  CREATE TABLE t2(d);
  SELECT * FROM t1 LEFT JOIN t2 ON (SELECT b FROM json_each ORDER BY 1);
} {}

# 2022-04-04 forum post https://sqlite.org/forum/forumpost/c082aeab43
do_execsql_test json-18.1 {
  SELECT json_valid('{"":5}');
} {1}
do_execsql_test json-18.2 {
  SELECT json_extract('{"":5}', '$.""');
} {5}
do_execsql_test json-18.3 {
  SELECT json_extract('[3,{"a":4,"":[5,{"hi":6},7]},8]', '$[1].""[1].hi');
} {6}
do_execsql_test json-18.4 {
  SELECT json_extract('[3,{"a":4,"":[5,{"hi":6},7]},8]', '$[1].""[1]."hi"');
} {6}
do_catchsql_test json-18.5 {
  SELECT json_extract('{"":8}', '$.');
} {1 {JSON path error near ''}}

finish_test