diff --git a/lib/string-parsing/escape-substring.js b/lib/string-parsing/escape-substring.js index 9a51e87..9f4d4b8 100644 --- a/lib/string-parsing/escape-substring.js +++ b/lib/string-parsing/escape-substring.js @@ -1,7 +1,5 @@ 'use strict' -const escapeFilterValue = require('../utils/escape-filter-value') - /** * In an extensible filter, the righthand size of the filter can have * substrings delimeted by `*` characters, e.g. `foo=*foo*bar*baz*`. This @@ -25,9 +23,9 @@ module.exports = function escapeSubstring (str) { throw Error('extensible filter delimiter missing') } - out.initial = escapeFilterValue(fields.shift()) - out.final = escapeFilterValue(fields.pop()) - Array.prototype.push.apply(out.any, fields.map(escapeFilterValue)) + out.initial = fields.shift() + out.final = fields.pop() + Array.prototype.push.apply(out.any, fields) return out } diff --git a/lib/string-parsing/escape-substring.test.js b/lib/string-parsing/escape-substring.test.js index 0c429ae..9857096 100644 --- a/lib/string-parsing/escape-substring.test.js +++ b/lib/string-parsing/escape-substring.test.js @@ -11,19 +11,25 @@ tap.test('throws if separator missing', async t => { }) tap.test('escapes an initial only string', async t => { - const expected = { initial: 'f\\28o', final: '', any: [] } + const expected = { initial: 'f(o', final: '', any: [] } const result = escapeSubstring('f(o*') t.strictSame(expected, result) }) tap.test('escapes string with initial and final', async t => { - const expected = { initial: 'f\\28o', final: 'bar', any: [] } + const expected = { initial: 'f(o', final: 'bar', any: [] } const result = escapeSubstring('f(o*bar') t.strictSame(expected, result) }) tap.test('escapes string with initial, final, and any', async t => { - const expected = { initial: 'f\\28o', final: 'b\\29f', any: ['bar', 'baz'] } + const expected = { initial: 'f(o', final: 'b)f', any: ['bar', 'baz'] } const result = escapeSubstring('f(o*bar*baz*b)f') t.strictSame(expected, result) }) + +tap.test('escapes string with any only and containing a non ascii character', async t => { + const expected = { initial: '', final: '', any: ['réseau'] } + const result = escapeSubstring('*réseau*') + t.strictSame(expected, result) +}) diff --git a/lib/string-parsing/parse-expression.test.js b/lib/string-parsing/parse-expression.test.js index e90d33e..2690329 100644 --- a/lib/string-parsing/parse-expression.test.js +++ b/lib/string-parsing/parse-expression.test.js @@ -102,5 +102,14 @@ tap.test('parses filter with non-ascii characters', t => { t.equal(result.toString(), '(cn=\\c3\\b8)') }) + t.test('*réseau*', async t => { + const result = parse('cn=*réseau*') + t.type(result, SubstringFilter) + t.equal(result.toString(), '(cn=*r\\c3\\a9seau*)') + t.equal(result.initial, '') + t.equal(result.final, '') + t.strictSame(result.any, ['réseau']) + }) + t.end() })