Skip to content

Commit

Permalink
fix(parser): normalize array keys before use
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Kristian Flaatten committed Jul 27, 2016
1 parent 9b37a8f commit 43c15d4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ module.exports.prototype.parse = function parse(query) {
let key = k;
const val = query[key];

// normalize array keys
if (val instanceof Array) {
key = key.replace(/\[\]$/, '');
}

// whitelist
if (Object.keys(this.whitelist).length && !this.whitelist[key]) {
return;
Expand All @@ -219,13 +224,15 @@ module.exports.prototype.parse = function parse(query) {
// string key
if (typeof val === 'string' && !this.keyRegex.test(key)) {
return;

// array key
} else if (val instanceof Array && !this.arrRegex.test(key)) {
return;
}

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

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

0 comments on commit 43c15d4

Please sign in to comment.