From ecfefa7ff0037ce2c6bc0d0bbd8b1a2c48a4cbc7 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 18 Sep 2019 14:35:10 -0500 Subject: [PATCH] fix escapedToHex capturing \ --- lib/filters/index.js | 5 ++--- test/filters/parse.test.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/filters/index.js b/lib/filters/index.js index 75774e2..d86eba4 100644 --- a/lib/filters/index.js +++ b/lib/filters/index.js @@ -165,14 +165,13 @@ 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) { + return str.replace(/\\([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 + return '\\' + hexCode }) } diff --git a/test/filters/parse.test.js b/test/filters/parse.test.js index 5eb6a94..83f0599 100644 --- a/test/filters/parse.test.js +++ b/test/filters/parse.test.js @@ -26,6 +26,16 @@ test('GH-50 = in filter', function (t) { 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) { const str = '(foo=bar\\()' const f = parse(str)