Upstream spencermountain/compromise state of the touched files before 0866b22381

This commit is contained in:
upstream committed 2026-10-14 19:27:14 +02:00
1 parent aa0091324b
commit e86878b0f3
2 files changed
+70 -12

No files matched your search

@@ -31,7 +31,7 @@ const stripBoth = function (str) {
return str return str
} }
// //
const parseToken = function (w, opts, aliases) { const parseToken = function (w, opts) {
const obj = {} const obj = {}
//collect any flags (do it twice) //collect any flags (do it twice)
for (let i = 0; i < 2; i += 1) { for (let i = 0; i < 2; i += 1) {
@@ -73,7 +73,7 @@ const parseToken = function (w, opts, aliases) {
} }
} }
//back-flags //back-flags
if (end(w) === '+' && !w.endsWith('\\+')) { if (end(w) === '+') {
obj.greedy = true obj.greedy = true
w = stripEnd(w) w = stripEnd(w)
} }
@@ -98,7 +98,7 @@ const parseToken = function (w, opts, aliases) {
} }
//regex //regex
if (start(w) === '/' && end(w) === '/' && w.length > 2) { if (start(w) === '/' && end(w) === '/') {
w = stripBoth(w) w = stripBoth(w)
if (opts.caseSensitive) { if (opts.caseSensitive) {
obj.use = 'text' obj.use = 'text'
@@ -156,7 +156,7 @@ const parseToken = function (w, opts, aliases) {
obj.choices = obj.choices.filter(s => s) obj.choices = obj.choices.filter(s => s)
//recursion alert! //recursion alert!
obj.choices = obj.choices.map(str => { obj.choices = obj.choices.map(str => {
return str.split(/ /g).map(s => parseToken(s, opts, aliases)) return str.split(/ /g).map(s => parseToken(s, opts))
}) })
w = '' w = ''
} }
@@ -197,12 +197,8 @@ const parseToken = function (w, opts, aliases) {
} }
//do the actual token content //do the actual token content
if (start(w) === '#') { if (start(w) === '#') {
const name = stripStart(w) obj.tag = stripStart(w)
obj.tag = aliases?.[name] obj.tag = titleCase(obj.tag)
if (!obj.tag) {
obj.tag = titleCase(name)
obj.tag = aliases?.[obj.tag] || obj.tag
}
return obj return obj
} }
//dynamic function on a term object //dynamic function on a term object
@@ -225,8 +221,6 @@ const parseToken = function (w, opts, aliases) {
//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 {
+64
View File
@@ -0,0 +1,64 @@
import test from 'tape'
import nlp from '../_lib.js'
const here = '[one/encoding] '
// test('encoding-match:', function (t) {
// let r = nlp('it is * nice')
// let str = r.match('is \\*').out().trim()
// t.equal(str, 'is *', 'encode asterix')
// r = nlp('it is + nice');
// str = r.match('is \\+ nice').trim().out();
// t.equal(str, 'is + nice', 'encode plus');
// 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')
t.equal(r.has(`#Foo`), false, here + 'tag')
t.equal(r.has(`(upcoming|backburner)`), false, here + 'anyOf')
t.equal(r.has(`lala+`), false, here + 'manyOf')
t.equal(r.has(`nword{2,4}`), false, here + 'someOf')
t.end()
})
test('reserved-word-in-match:', function (t) {
const r = nlp('fo foo fulala repeat')
t.equal(r.has(`constructor`), false, here + 'single')
t.equal(r.has(`#constructor`), false, here + 'tag')
t.equal(r.has(`(upcoming|constructor)`), false, here + 'anyOf')
t.equal(r.has(`constructor+`), false, here + 'manyOf')
t.equal(r.has(`constructor{2,4}`), false, here + 'someOf')
t.end()
})
test('test-infinite-loop', function (t) {
const weirdDoc = nlp('^ ? * . + $')
weirdDoc.match('is?')
weirdDoc.match('.?')
weirdDoc.match('*')
weirdDoc.match('.+')
weirdDoc.match('+')
weirdDoc.match('?')
weirdDoc.match('.')
weirdDoc.match('? * . +')
weirdDoc.not('?')
weirdDoc.not('*')
weirdDoc.not('^')
weirdDoc.not('$')
weirdDoc.not('+')
weirdDoc.not('? * . +')
t.ok(true, here + 'didnt regress')
let str = 'And you are?. Marshal'
let have = nlp(str).all().out()
t.equal(have, str, here + 'regression #1')
str = `- where is she.Oh. you guys don't know?`
have = nlp(str).all().out()
t.equal(have, str, here + 'regression #2')
t.end()
})