Fix query unpacking breaking $regex operator
If the regex string can be parsed as a date or a number, the unpacked query will be rejected by MongoDB because $regex operator only accepts a string.
This commit is contained in:
1 parent
8f827997cd
commit
aa12b7c724
1 file changed
+13
-1
+13
-1
@@ -54,6 +54,17 @@ function normalize(input): any {
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EXPAND_OPS = new Set([
|
||||||
|
"$eq",
|
||||||
|
"$gt",
|
||||||
|
"$gte",
|
||||||
|
"$in",
|
||||||
|
"$lt",
|
||||||
|
"$lte",
|
||||||
|
"$ne",
|
||||||
|
"$nin",
|
||||||
|
]);
|
||||||
|
|
||||||
function expandValue(value: unknown): unknown[] {
|
function expandValue(value: unknown): unknown[] {
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
let a = [];
|
let a = [];
|
||||||
@@ -71,7 +82,8 @@ function expandValue(value: unknown): unknown[] {
|
|||||||
const values = [];
|
const values = [];
|
||||||
for (const [k, v] of Object.entries(value)) {
|
for (const [k, v] of Object.entries(value)) {
|
||||||
keys.push(k);
|
keys.push(k);
|
||||||
values.push(expandValue(v));
|
if (EXPAND_OPS.has(k)) values.push(expandValue(v));
|
||||||
|
else values.push([v]);
|
||||||
indices.push(0);
|
indices.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user