From d5cf19bd9ecfa5be0428074f3f517b72dd0b9be1 Mon Sep 17 00:00:00 2001 From: Mark Cavage Date: Wed, 14 Mar 2012 09:06:03 -0700 Subject: [PATCH] Finish up #65 (lint and missing check) --- lib/filters/escape.js | 20 +++++++++++--------- lib/filters/substr_filter.js | 16 +++++++++++----- package.json | 3 ++- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/filters/escape.js b/lib/filters/escape.js index e8706c9..c9aea4e 100644 --- a/lib/filters/escape.js +++ b/lib/filters/escape.js @@ -9,26 +9,28 @@ * (filename=C:\MyFile) (filename=C:\5cMyFile) * * Use substr_filter to avoid having * ecsaped. + * + * @author [Austin King](https://github.com/ozten) */ exports.escape = function (inp) { - if (typeof inp === 'string') { - var esc = ""; - for (var i=0; i < inp.length; i++) { + if (typeof (inp) === 'string') { + var esc = ''; + for (var i = 0; i < inp.length; i++) { switch (inp[i]) { case '*': - esc += "\\2a"; + esc += '\\2a'; break; case '(': - esc += "\\28"; + esc += '\\28'; break; case ')': - esc += "\\29"; + esc += '\\29'; break; case '\\': - esc += "\\5c"; + esc += '\\5c'; break; case '\0': - esc += "\\00"; + esc += '\\00'; break; default: esc += inp[i]; @@ -40,4 +42,4 @@ exports.escape = function (inp) { } else { return inp; } -}; \ No newline at end of file +}; diff --git a/lib/filters/substr_filter.js b/lib/filters/substr_filter.js index a8045fa..e3672d6 100644 --- a/lib/filters/substr_filter.js +++ b/lib/filters/substr_filter.js @@ -14,24 +14,30 @@ var Protocol = require('../protocol'); ///--- API function SubstringFilter(options) { + var _any; if (typeof (options) === 'object') { if (!options.attribute || typeof (options.attribute) !== 'string') throw new TypeError('options.attribute (string) required'); this.attribute = escape(options.attribute); this.initial = options.initial ? escape(options.initial) : null; - this.any = options.any ? options.any.slice(0) : []; - this['final'] = options['final'] || null; + _any = options.any ? options.any.slice(0) : []; + this['final'] = escape(options['final']) || null; } else { options = {}; } - if (!this.any) - this.any = []; + if (!_any) + _any = []; + + this.any = []; + var self = this; + _any.forEach(function (a) { + self.any.push(escape(a)); + }); options.type = Protocol.FILTER_SUBSTRINGS; Filter.call(this, options); - var self = this; this.__defineGetter__('json', function () { return { type: 'SubstringMatch', diff --git a/package.json b/package.json index 10dd2d7..10a1b51 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "author": "Mark Cavage ", "contributors": [ + "Craig Baker" + "Austin King " "Mathieu Lecarme >", "Trent Mick ", "Yunong Xiao ", - "Craig Baker" ], "name": "ldapjs", "homepage": "http://ldapjs.org",