@@ -1581,17 +1581,23 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1581
1581
}
1582
1582
}
1583
1583
}
1584
+ else if (jspAutoWrap (cxt ))
1585
+ res = recursiveExecuteNext (cxt , jsp , NULL , jb , found , true);
1584
1586
else if (!jspIgnoreStructuralErrors (cxt ))
1585
1587
res = jperMakeError (ERRCODE_JSON_ARRAY_NOT_FOUND );
1586
1588
break ;
1587
1589
1588
1590
case jpiIndexArray :
1589
- if (JsonbType (jb ) == jbvArray )
1591
+ if (JsonbType (jb ) == jbvArray || jspAutoWrap ( cxt ) )
1590
1592
{
1591
1593
int innermostArraySize = cxt -> innermostArraySize ;
1592
1594
int i ;
1593
1595
int size = JsonbArraySize (jb );
1594
1596
bool binary = jb -> type == jbvBinary ;
1597
+ bool singleton = size < 0 ;
1598
+
1599
+ if (singleton )
1600
+ size = 1 ;
1595
1601
1596
1602
cxt -> innermostArraySize = size ; /* for LAST evaluation */
1597
1603
@@ -1640,16 +1646,32 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1640
1646
1641
1647
for (index = index_from ; index <= index_to ; index ++ )
1642
1648
{
1643
- JsonbValue * v = binary ?
1644
- getIthJsonbValueFromContainer (jb -> val .binary .data ,
1645
- (uint32 ) index ) :
1646
- & jb -> val .array .elems [index ];
1649
+ JsonbValue * v ;
1650
+ bool copy ;
1651
+
1652
+ if (singleton )
1653
+ {
1654
+ v = jb ;
1655
+ copy = true;
1656
+ }
1657
+ else if (binary )
1658
+ {
1659
+ v = getIthJsonbValueFromContainer (jb -> val .binary .data ,
1660
+ (uint32 ) index );
1647
1661
1648
- if (v == NULL )
1649
- continue ;
1662
+ if (v == NULL )
1663
+ continue ;
1664
+
1665
+ copy = false;
1666
+ }
1667
+ else
1668
+ {
1669
+ v = & jb -> val .array .elems [index ];
1670
+ copy = true;
1671
+ }
1650
1672
1651
1673
res = recursiveExecuteNext (cxt , jsp , & elem , v , found ,
1652
- ! binary );
1674
+ copy );
1653
1675
1654
1676
if (jperIsError (res ))
1655
1677
break ;
@@ -2285,11 +2307,6 @@ recursiveExecute(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
2285
2307
case jpiKeyValue :
2286
2308
return recursiveExecuteUnwrap (cxt , jsp , jb , found );
2287
2309
2288
- case jpiAnyArray :
2289
- case jpiIndexArray :
2290
- jb = wrapItem (jb );
2291
- break ;
2292
-
2293
2310
default :
2294
2311
break ;
2295
2312
}
0 commit comments