@@ -1857,9 +1857,8 @@ export class Stack {
1857
1857
$or : [ ] ,
1858
1858
}
1859
1859
1860
- const sanitizedQueryBucket = this . sanitizeQueryBucket ( queryBucket ) ;
1861
1860
for ( let i = 0 , j = paths . length ; i < j ; i ++ ) {
1862
- this . fetchPathDetails ( entries , locale , paths [ i ] . split ( '.' ) , sanitizedQueryBucket , shelf , true , entries , 0 )
1861
+ this . fetchPathDetails ( entries , locale , paths [ i ] . split ( '.' ) , queryBucket , shelf , true , entries , 0 )
1863
1862
}
1864
1863
1865
1864
if ( shelf . length === 0 ) {
@@ -1870,7 +1869,7 @@ export class Stack {
1870
1869
content_type_uid : this . types . assets ,
1871
1870
locale,
1872
1871
} , this . collectionNames ) )
1873
- . find ( sanitizedQueryBucket ) // Use sanitized query here
1872
+ . find ( queryBucket )
1874
1873
. project ( {
1875
1874
_content_type_uid : 0 ,
1876
1875
_id : 0 ,
@@ -1934,6 +1933,7 @@ export class Stack {
1934
1933
private fetchPathDetails ( data : any , locale : string , pathArr : string [ ] , queryBucket : IQuery , shelf ,
1935
1934
assetsOnly = false , parent , pos , counter = 0 ) {
1936
1935
if ( counter === ( pathArr . length ) ) {
1936
+ queryBucket = this . sanitizeQueryBucket ( queryBucket )
1937
1937
if ( data && typeof data === 'object' ) {
1938
1938
if ( data instanceof Array && data . length ) {
1939
1939
data . forEach ( ( elem , idx ) => {
@@ -2000,13 +2000,13 @@ export class Stack {
2000
2000
// tslint:disable-next-line: prefer-for-of
2001
2001
for ( let i = 0 ; i < data . length ; i ++ ) {
2002
2002
if ( data [ i ] [ currentField ] ) {
2003
- this . fetchPathDetails ( data [ i ] [ currentField ] , locale , pathArr , queryBucket , shelf , assetsOnly , data [ i ] ,
2003
+ this . fetchPathDetails ( data [ i ] [ currentField ] , locale , pathArr , this . sanitizeQueryBucket ( queryBucket ) , shelf , assetsOnly , data [ i ] ,
2004
2004
currentField , counter )
2005
2005
}
2006
2006
}
2007
2007
} else {
2008
2008
if ( data [ currentField ] ) {
2009
- this . fetchPathDetails ( data [ currentField ] , locale , pathArr , queryBucket , shelf , assetsOnly , data ,
2009
+ this . fetchPathDetails ( data [ currentField ] , locale , pathArr , this . sanitizeQueryBucket ( queryBucket ) , shelf , assetsOnly , data ,
2010
2010
currentField , counter )
2011
2011
}
2012
2012
}
@@ -2101,11 +2101,12 @@ export class Stack {
2101
2101
if ( ! this . sanityQueryAny ( query ) ) {
2102
2102
throw new Error ( 'Invalid query provided' ) ;
2103
2103
}
2104
+ const querySanitize = this . sanitizeQueryBucket ( query )
2104
2105
const schemas = await this . db . collection ( getCollectionName ( {
2105
2106
content_type_uid : this . types . content_types ,
2106
2107
locale,
2107
2108
} , this . collectionNames ) )
2108
- . find ( query )
2109
+ . find ( querySanitize )
2109
2110
. project ( {
2110
2111
_assets : 1 ,
2111
2112
_id : 0 ,
@@ -2196,11 +2197,12 @@ export class Stack {
2196
2197
if ( ! this . sanitizeIQuery ( query ) ) {
2197
2198
throw new Error ( 'Invalid queries provided' ) ;
2198
2199
}
2200
+ const sanitizeQuery = this . sanitizeQueryBucket ( query )
2199
2201
const result = await this . db . collection ( getCollectionName ( {
2200
2202
content_type_uid : 'entries' ,
2201
2203
locale,
2202
2204
} , this . collectionNames ) )
2203
- . find ( query )
2205
+ . find ( sanitizeQuery )
2204
2206
. project ( {
2205
2207
_content_type_uid : 0 ,
2206
2208
_id : 0 ,
@@ -2261,7 +2263,7 @@ export class Stack {
2261
2263
// iterate over each path in the entries and fetch the references
2262
2264
// while fetching, keep track of their location
2263
2265
for ( let i = 0 , j = paths . length ; i < j ; i ++ ) {
2264
- this . fetchPathDetails ( entries , locale , paths [ i ] . split ( '.' ) , queries , objectPointerList , true , entries , 0 )
2266
+ this . fetchPathDetails ( entries , locale , paths [ i ] . split ( '.' ) , this . sanitizeQueryBucket ( queries ) , objectPointerList , true , entries , 0 )
2265
2267
}
2266
2268
2267
2269
// even after traversing, if no references were found, simply return the entries found thusfar
@@ -2437,15 +2439,15 @@ export class Stack {
2437
2439
private sanitizeQueryBucket ( queryBucket : any ) : any {
2438
2440
// Validate basic structure
2439
2441
if ( ! queryBucket || typeof queryBucket !== 'object' ) {
2440
- return { $or : [ ] } ;
2442
+ return { $or : [ { _id : { $exists : true } } ] } ; // Default query that matches all documents
2441
2443
}
2442
2444
2443
2445
// Create a new sanitized query object
2444
2446
const sanitized = { $or : [ ] } ;
2445
2447
2446
2448
// Ensure $or is an array
2447
2449
if ( ! Array . isArray ( queryBucket . $or ) ) {
2448
- return sanitized ;
2450
+ return { $or : [ { _id : { $exists : true } } ] } ; // Default query that matches all documents
2449
2451
}
2450
2452
2451
2453
// Process each item in the $or array
@@ -2479,6 +2481,12 @@ export class Stack {
2479
2481
sanitized . $or . push ( safeItem ) ;
2480
2482
}
2481
2483
}
2484
+
2485
+ // If sanitized.$or is empty, use a default query that matches all documents
2486
+ if ( sanitized . $or . length === 0 ) {
2487
+ return { $or : [ { _id : { $exists : true } } ] } ;
2488
+ }
2489
+
2482
2490
return sanitized ;
2483
2491
}
2484
2492
}
0 commit comments