diff --git a/lib/filters/index.js b/lib/filters/index.js index feb0717..e44e305 100644 --- a/lib/filters/index.js +++ b/lib/filters/index.js @@ -171,9 +171,21 @@ function cloneFilter(input) { } } +function escapedToHex(str) { + return str.replace(/\\([0-9a-f][^0-9a-f]|[0-9a-f]$|[^0-9a-f]|$)/gi, function (match, p1) { + if (!p1) { + return '\\5c'; + } + + const hexCode = p1.charCodeAt(0).toString(16); + const rest = p1.substring(1); + return '\\' + hexCode + rest; + }); +} function parseString(str) { - var generic = parents.parse(str); + const hexStr = escapedToHex(str); + const generic = parents.parse(hexStr); // The filter object(s) return from ldap-filter.parse lack the toBer/parse // decoration that native ldapjs filter possess. cloneFilter adds that back. return cloneFilter(generic); diff --git a/package.json b/package.json index 272fde9..c178164 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "asn1": "0.2.3", "assert-plus": "^1.0.0", "backoff": "^2.5.0", - "ldap-filter": "^0.2.2", + "ldap-filter": "^0.3.3", "dashdash": "^1.14.0", "once": "^1.4.0", "vasync": "^1.6.4", diff --git a/test/filters/parse.test.js b/test/filters/parse.test.js index d564c07..d02ec30 100644 --- a/test/filters/parse.test.js +++ b/test/filters/parse.test.js @@ -52,28 +52,6 @@ test(') in filter', function (t) { }); -test('( in filter', function (t) { - var str = 'foo(bar=baz\\()'; - var f = parse(str); - t.ok(f); - t.equal(f.attribute, 'foo(bar'); - t.equal(f.value, 'baz()'); - t.equal(f.toString(), '(foo\\28bar=baz\\28\\29)'); - t.end(); -}); - - -test('( in filter', function (t) { - var str = 'foo)(&(bar=baz)('; - var f = parse(str); - t.ok(f); - t.equal(f.attribute, 'foo)(&(bar'); - t.equal(f.value, 'baz)('); - t.equal(f.toString(), '(foo\\29\\28&\\28bar=baz\\29\\28)'); - t.end(); -}); - - test('\\ in filter', function (t) { var str = '(foo=bar\\\\)'; var f = parse(str);