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

Commit

Permalink
Fix issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-samuel.tettekpoe committed Nov 16, 2023
1 parent 2f5fd6b commit 7e36ab8
Show file tree
Hide file tree
Showing 3 changed files with 6,864 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)
})
Loading

0 comments on commit 7e36ab8

Please sign in to comment.