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

Commit ecfefa7

Browse files
committed
fix escapedToHex capturing \
1 parent a113953 commit ecfefa7

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-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: 10 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\\'
31+
const f = parse(str)
32+
t.ok(f)
33+
t.equal(f.attribute, 'foo')
34+
t.equal(f.value, 'bar(abcdefghi\\')
35+
t.equal(f.toString(), '(foo=bar\\28abcdefghi\\5c)')
36+
t.end()
37+
})
38+
2939
test('( in filter', function (t) {
3040
const str = '(foo=bar\\()'
3141
const f = parse(str)

0 commit comments

Comments
 (0)