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

Commit dd2a722

Browse files
authored
Merge pull request #565 from UziTech/fix-escapedtohex
Fix escapedToHex
2 parents a113953 + ed70fd7 commit dd2a722

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lib/filters/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,13 @@ function cloneFilter (input) {
165165
}
166166

167167
function escapedToHex (str) {
168-
return str.replace(/\\([0-9a-f][^0-9a-f]|[0-9a-f]$|[^0-9a-f]|$)/gi, function (match, p1) {
168+
return str.replace(/\\([0-9a-f](?![0-9a-f])|[^0-9a-f]|$)/gi, function (match, p1) {
169169
if (!p1) {
170170
return '\\5c'
171171
}
172172

173173
const hexCode = p1.charCodeAt(0).toString(16)
174-
const rest = p1.substring(1)
175-
return '\\' + hexCode + rest
174+
return '\\' + hexCode
176175
})
177176
}
178177

test/filters/parse.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ test('GH-50 = in filter', function (t) {
2626
t.end()
2727
})
2828

29+
test('convert to hex code', function (t) {
30+
const str = 'foo=bar\\(abcd\\e\\fg\\h\\69\\a'
31+
const f = parse(str)
32+
t.ok(f)
33+
t.equal(f.attribute, 'foo')
34+
t.equal(f.value, 'bar(abcdefghia')
35+
t.equal(f.toString(), '(foo=bar\\28abcdefghia)')
36+
t.end()
37+
})
38+
2939
test('( in filter', function (t) {
3040
const str = '(foo=bar\\()'
3141
const f = parse(str)
@@ -56,6 +66,16 @@ test('\\ in filter', function (t) {
5666
t.end()
5767
})
5868

69+
test('not escaped \\ at end of filter', function (t) {
70+
const str = 'foo=bar\\'
71+
const f = parse(str)
72+
t.ok(f)
73+
t.equal(f.attribute, 'foo')
74+
t.equal(f.value, 'bar\\')
75+
t.equal(f.toString(), '(foo=bar\\5c)')
76+
t.end()
77+
})
78+
5979
test('* in equality filter', function (t) {
6080
const str = '(foo=bar\\*)'
6181
const f = parse(str)

0 commit comments

Comments
 (0)