fix escapedToHex capturing \
This commit is contained in:
parent
a113953e0d
commit
ecfefa7ff0
|
@ -165,14 +165,13 @@ function cloneFilter (input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapedToHex (str) {
|
function escapedToHex (str) {
|
||||||
return str.replace(/\\([0-9a-f][^0-9a-f]|[0-9a-f]$|[^0-9a-f]|$)/gi, function (match, p1) {
|
return str.replace(/\\([0-9a-f](?![0-9a-f])|[^0-9a-f]|$)/gi, function (match, p1) {
|
||||||
if (!p1) {
|
if (!p1) {
|
||||||
return '\\5c'
|
return '\\5c'
|
||||||
}
|
}
|
||||||
|
|
||||||
const hexCode = p1.charCodeAt(0).toString(16)
|
const hexCode = p1.charCodeAt(0).toString(16)
|
||||||
const rest = p1.substring(1)
|
return '\\' + hexCode
|
||||||
return '\\' + hexCode + rest
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,16 @@ test('GH-50 = in filter', function (t) {
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('convert to hex code', function (t) {
|
||||||
|
const str = 'foo=bar\\(abcd\\e\\fg\\h\\69\\'
|
||||||
|
const f = parse(str)
|
||||||
|
t.ok(f)
|
||||||
|
t.equal(f.attribute, 'foo')
|
||||||
|
t.equal(f.value, 'bar(abcdefghi\\')
|
||||||
|
t.equal(f.toString(), '(foo=bar\\28abcdefghi\\5c)')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
test('( in filter', function (t) {
|
test('( in filter', function (t) {
|
||||||
const str = '(foo=bar\\()'
|
const str = '(foo=bar\\()'
|
||||||
const f = parse(str)
|
const f = parse(str)
|
||||||
|
|
Loading…
Reference in New Issue