fix match escaping for + and /, refs #726

This commit is contained in:
dualfroz committed 2026-10-14 19:36:47 +02:00
1 parent 2f2fac89a0
commit aa0091324b
2 files changed
+20 -2

No files matched your search

+16
View File
@@ -2,6 +2,22 @@ import test from 'tape'
import nlp from '../../lib/one.js'
const here = '[one/match/encoding] '
test('encoding-match:', function (t) {
let doc = nlp('it is + nice')
t.equal(doc.match('is \\+ nice').text(), 'is + nice', here + 'encode plus')
t.deepEqual(doc.match('\\+').out('array'), ['+'], here + 'plus alone')
t.deepEqual(doc.match('!\\+').out('array'), ['it', 'is', 'nice'], here + 'negative plus')
doc = nlp('a / b c d')
t.deepEqual(doc.match('\\/').out('array'), ['/'], here + 'encode slash')
t.deepEqual(doc.match('/').out('array'), ['/'], here + 'slash is not a regex')
t.equal(doc.match('a \\/ b').text(), 'a / b', here + 'slash in sequence')
doc = nlp('4 / 2 + 1')
t.deepEqual(doc.match('(\\+|\\/)').out('array'), ['/', '+'], here + 'encoded choices')
t.end()
})
test('reserved-word-in-src:', function (t) {
const r = nlp('buy eggs constructor yeah prototype')
t.equal(r.has(`backburner`), false, here + 'single')