fix match escaping for + and /, refs #726
This commit is contained in:
1 parent
e86878b0f3
commit
608ac25b7b
2 files changed
+21
-11
No files matched your search
@@ -73,7 +73,7 @@ const parseToken = function (w, opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//back-flags
|
//back-flags
|
||||||
if (end(w) === '+') {
|
if (end(w) === '+' && !w.endsWith('\\+')) {
|
||||||
obj.greedy = true
|
obj.greedy = true
|
||||||
w = stripEnd(w)
|
w = stripEnd(w)
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ const parseToken = function (w, opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//regex
|
//regex
|
||||||
if (start(w) === '/' && end(w) === '/') {
|
if (start(w) === '/' && end(w) === '/' && w.length > 2) {
|
||||||
w = stripBoth(w)
|
w = stripBoth(w)
|
||||||
if (opts.caseSensitive) {
|
if (opts.caseSensitive) {
|
||||||
obj.use = 'text'
|
obj.use = 'text'
|
||||||
@@ -221,6 +221,8 @@ const parseToken = function (w, opts) {
|
|||||||
//somehow handle encoded-chars?
|
//somehow handle encoded-chars?
|
||||||
w = w.replace('\\*', '*')
|
w = w.replace('\\*', '*')
|
||||||
w = w.replace('\\.', '.')
|
w = w.replace('\\.', '.')
|
||||||
|
w = w.replace('\\+', '+')
|
||||||
|
w = w.replace('\\/', '/')
|
||||||
if (opts.caseSensitive) {
|
if (opts.caseSensitive) {
|
||||||
obj.use = 'text'
|
obj.use = 'text'
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,17 +2,25 @@ import test from 'tape'
|
|||||||
import nlp from '../_lib.js'
|
import nlp from '../_lib.js'
|
||||||
const here = '[one/encoding] '
|
const here = '[one/encoding] '
|
||||||
|
|
||||||
// test('encoding-match:', function (t) {
|
test('encoding-match:', function (t) {
|
||||||
// let r = nlp('it is * nice')
|
// let r = nlp('it is * nice')
|
||||||
// let str = r.match('is \\*').out().trim()
|
// let str = r.match('is \\*').out().trim()
|
||||||
// t.equal(str, 'is *', 'encode asterix')
|
// t.equal(str, 'is *', 'encode asterix')
|
||||||
|
|
||||||
// r = nlp('it is + nice');
|
let doc = nlp('it is + nice')
|
||||||
// str = r.match('is \\+ nice').trim().out();
|
t.equal(doc.match('is \\+ nice').text(), 'is + nice', here + 'encode plus')
|
||||||
// t.equal(str, 'is + nice', 'encode plus');
|
t.deepEqual(doc.match('\\+').out('array'), ['+'], here + 'plus alone')
|
||||||
|
t.deepEqual(doc.match('!\\+').out('array'), ['it', 'is', 'nice'], here + 'negative plus')
|
||||||
|
|
||||||
// t.end()
|
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) {
|
test('reserved-word-in-src:', function (t) {
|
||||||
const r = nlp('buy eggs constructor yeah prototype')
|
const r = nlp('buy eggs constructor yeah prototype')
|
||||||
|
|||||||
Reference in new issue
Block a user