Some fixes in unpacking of queries with regex

This commit is contained in:
Zaid Abdulla committed 2016-05-18 00:44:52 +03:00
1 parent 3fa299cbee
commit 9fde3ad5d5
2 files changed
+15 -6

No files matched your search

+3 -3
View File
@@ -68,7 +68,7 @@ normalizers.default = (input, normType) ->
r = stringToRegexp(input) r = stringToRegexp(input)
if r isnt false if r isnt false
vals.push({'$regex' : r}) vals.push(r)
return vals return vals
return input return input
@@ -90,7 +90,7 @@ normalizers.date = (input, normType) ->
normalizers.string = (input, normType) -> normalizers.string = (input, normType) ->
if normType is 'query' if normType is 'query'
if (m = /^\/(.*?)\/(g?i?m?y?)$/.exec(input)) if (m = /^\/(.*?)\/(g?i?m?y?)$/.exec(input))
return [{'$regex' : new RegExp(m[1], m[2])}, input] return [new RegExp(m[1], m[2]), input]
return input return input
@@ -124,7 +124,7 @@ normalizers.mac = (input, normType) ->
if input.length == 17 if input.length == 17
return [input, input.toLowerCase()] return [input, input.toLowerCase()]
return {'$regex' : new RegExp(input, 'i')} return new RegExp(input, 'i')
exports.normalize = (path, value, normType) -> exports.normalize = (path, value, normType) ->
+12 -3
View File
@@ -51,8 +51,17 @@ expandValue = (param, value) ->
while i < indices.length while i < indices.length
obj = {} obj = {}
for i in [0...keys.length] for i in [0...keys.length]
if common.typeOf(values[i][indices[i]]) is common.REGEXP_TYPE
if keys[i] == '$ne'
obj['$not'] = values[i][indices[i]]
continue
else if keys[i] == '$not' and common.typeOf(values[i][indices[i]]) isnt common.OBJECT_TYPE
# Only a regex or decoument (object) are allowed within a $not operator.
# This is needed in order to discard string from which a regex is generated.
continue
obj[keys[i]] = values[i][indices[i]] obj[keys[i]] = values[i][indices[i]]
objs.push(obj) objs.push(obj) if Object.keys(obj).length
for i in [0...indices.length] for i in [0...indices.length]
indices[i] += 1 indices[i] += 1
@@ -75,7 +84,7 @@ permute = (param, val, aliases) ->
values = expandValue(k, val) values = expandValue(k, val)
if k[k.lastIndexOf('.') + 1] != '_' if k[k.lastIndexOf('.') + 1] != '_'
k += '._value' k += '._value'
for v in values for v in values
obj = {} obj = {}
obj[k] = v obj[k] = v
@@ -96,7 +105,7 @@ expand = (query, aliases) ->
conditions = permute(k, v, aliases) conditions = permute(k, v, aliases)
if conditions.length > 1 if conditions.length > 1
new_query['$and'] ?= [] new_query['$and'] ?= []
if v?['$ne']? if v?['$ne']? or v?['$nin']? or v?['$not']?
for c in conditions for c in conditions
new_query['$and'].push(c) new_query['$and'].push(c)
else else