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:
Zaid Abdulla committed 2021-11-08 14:21:14 -08:00
1 parent 8f827997cd
commit aa12b7c724
1 file changed
+13 -1
+13 -1
View File
@@ -54,6 +54,17 @@ function normalize(input): any {
return input;
}
const EXPAND_OPS = new Set([
"$eq",
"$gt",
"$gte",
"$in",
"$lt",
"$lte",
"$ne",
"$nin",
]);
function expandValue(value: unknown): unknown[] {
if (Array.isArray(value)) {
let a = [];
@@ -71,7 +82,8 @@ function expandValue(value: unknown): unknown[] {
const values = [];
for (const [k, v] of Object.entries(value)) {
keys.push(k);
values.push(expandValue(v));
if (EXPAND_OPS.has(k)) values.push(expandValue(v));
else values.push([v]);
indices.push(0);
}