Skip to content

Commit

Permalink
Fix issue ldapjs#8
Browse files Browse the repository at this point in the history
  • Loading branch information
PositroniumJS committed Nov 22, 2023
1 parent 2f5fd6b commit aadb347
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
8 changes: 3 additions & 5 deletions lib/string-parsing/escape-substring.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
12 changes: 9 additions & 3 deletions lib/string-parsing/escape-substring.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
9 changes: 9 additions & 0 deletions lib/string-parsing/parse-expression.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

0 comments on commit aadb347

Please sign in to comment.