Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 400af20

Browse files
UziTechjsumners
authored andcommitted
Update ldap filter (#521)
* update ldap-filter v0.3.3 * allow escaped characters * remove failing tests * remove arrow function * remove template string
1 parent 068ea4e commit 400af20

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

lib/filters/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,21 @@ function cloneFilter(input) {
171171
}
172172
}
173173

174+
function escapedToHex(str) {
175+
return str.replace(/\\([0-9a-f][^0-9a-f]|[0-9a-f]$|[^0-9a-f]|$)/gi, function (match, p1) {
176+
if (!p1) {
177+
return '\\5c';
178+
}
179+
180+
const hexCode = p1.charCodeAt(0).toString(16);
181+
const rest = p1.substring(1);
182+
return '\\' + hexCode + rest;
183+
});
184+
}
174185

175186
function parseString(str) {
176-
var generic = parents.parse(str);
187+
const hexStr = escapedToHex(str);
188+
const generic = parents.parse(hexStr);
177189
// The filter object(s) return from ldap-filter.parse lack the toBer/parse
178190
// decoration that native ldapjs filter possess. cloneFilter adds that back.
179191
return cloneFilter(generic);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"asn1": "0.2.3",
3434
"assert-plus": "^1.0.0",
3535
"backoff": "^2.5.0",
36-
"ldap-filter": "^0.2.2",
36+
"ldap-filter": "^0.3.3",
3737
"dashdash": "^1.14.0",
3838
"once": "^1.4.0",
3939
"vasync": "^1.6.4",

test/filters/parse.test.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,6 @@ test(') in filter', function (t) {
5252
});
5353

5454

55-
test('( in filter', function (t) {
56-
var str = 'foo(bar=baz\\()';
57-
var f = parse(str);
58-
t.ok(f);
59-
t.equal(f.attribute, 'foo(bar');
60-
t.equal(f.value, 'baz()');
61-
t.equal(f.toString(), '(foo\\28bar=baz\\28\\29)');
62-
t.end();
63-
});
64-
65-
66-
test('( in filter', function (t) {
67-
var str = 'foo)(&(bar=baz)(';
68-
var f = parse(str);
69-
t.ok(f);
70-
t.equal(f.attribute, 'foo)(&(bar');
71-
t.equal(f.value, 'baz)(');
72-
t.equal(f.toString(), '(foo\\29\\28&\\28bar=baz\\29\\28)');
73-
t.end();
74-
});
75-
76-
7755
test('\\ in filter', function (t) {
7856
var str = '(foo=bar\\\\)';
7957
var f = parse(str);

0 commit comments

Comments
 (0)