Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 43c15d4

Browse files
author
Hans Kristian Flaatten
committed
fix(parser): normalize array keys before use
1 parent 9b37a8f commit 43c15d4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ module.exports.prototype.parse = function parse(query) {
201201
let key = k;
202202
const val = query[key];
203203

204+
// normalize array keys
205+
if (val instanceof Array) {
206+
key = key.replace(/\[\]$/, '');
207+
}
208+
204209
// whitelist
205210
if (Object.keys(this.whitelist).length && !this.whitelist[key]) {
206211
return;
@@ -219,13 +224,15 @@ module.exports.prototype.parse = function parse(query) {
219224
// string key
220225
if (typeof val === 'string' && !this.keyRegex.test(key)) {
221226
return;
227+
228+
// array key
229+
} else if (val instanceof Array && !this.arrRegex.test(key)) {
230+
return;
222231
}
223232

224233
// array key
225-
if (val instanceof Array && this.arrRegex.test(key)) {
234+
if (val instanceof Array) {
226235
if (this.ops.indexOf('$in') >= 0 && val.length > 0) {
227-
// remove [] at end of key name (unless it has already been removed)
228-
key = key.replace(/\[\]$/, '');
229236
res[key] = {};
230237

231238
for (let i = 0; i < val.length; i++) {

0 commit comments

Comments
 (0)