Improved MAC normalization
This commit is contained in:
1 parent
eb92d35b51
commit
03e57616f7
2 files changed
+27
-4
No files matched your search
@@ -5,6 +5,7 @@ NUMBER_TYPE = '[object Number]'
|
|||||||
STRING_TYPE = '[object String]'
|
STRING_TYPE = '[object String]'
|
||||||
ARRAY_TYPE = '[object Array]'
|
ARRAY_TYPE = '[object Array]'
|
||||||
OBJECT_TYPE = '[object Object]'
|
OBJECT_TYPE = '[object Object]'
|
||||||
|
REGEXP_TYPE = '[object RegExp]'
|
||||||
|
|
||||||
|
|
||||||
typeOf = (obj) ->
|
typeOf = (obj) ->
|
||||||
|
|||||||
+26
-4
@@ -71,15 +71,37 @@ normalizers.string = (input, normType) ->
|
|||||||
input
|
input
|
||||||
|
|
||||||
|
|
||||||
|
colonizeMac = (input) ->
|
||||||
|
if (i = input.indexOf(':')) != -1
|
||||||
|
i = if (i % 2) == 0 then 0 else 1
|
||||||
|
while i < input.length
|
||||||
|
if input[i-1] != ':' and input[i-2] != ':'
|
||||||
|
if input[i] != ':' and i != 0
|
||||||
|
input = input.substring(0, i) + ':' + input.substring(i)
|
||||||
|
++i
|
||||||
|
++i
|
||||||
|
++ i
|
||||||
|
return input
|
||||||
|
else
|
||||||
|
return input.replace(/[0-9A-F]{1}(?!$)/g, '$&:?')
|
||||||
|
|
||||||
|
|
||||||
normalizers.mac = (input, normType) ->
|
normalizers.mac = (input, normType) ->
|
||||||
if normType isnt 'query'
|
if normType isnt 'query'
|
||||||
return input
|
return input
|
||||||
|
|
||||||
input = input.toUpperCase().replace(/[^0-9A-F]/g, '')
|
input = input.trim().toUpperCase().replace(/[^0-9A-F\*\-\:]/g, '').replace(/[\-\:]/g, ':')
|
||||||
if input.length == 12
|
|
||||||
return input.substring(2).replace(/[0-9A-F]{2}(?!$)/g, '$&:')
|
|
||||||
|
|
||||||
return {'$regex' : eval('/' + input.replace(/[0-9A-F]{1}(?!$)/g, '$&:?') + '/')}
|
if input.indexOf('*') != -1
|
||||||
|
input = (colonizeMac(a) for a in input.split('*')).join('*')
|
||||||
|
return stringToRegexp(input, false)
|
||||||
|
|
||||||
|
input = colonizeMac(input)
|
||||||
|
|
||||||
|
if input.length == 17
|
||||||
|
return input
|
||||||
|
|
||||||
|
return {'$regex' : eval('/' + input + '/')}
|
||||||
|
|
||||||
|
|
||||||
exports.normalize = (path, value, normType) ->
|
exports.normalize = (path, value, normType) ->
|
||||||
|
|||||||
Reference in new issue
Block a user