fix an infinite loop in editor search with /^/ or /$/ (#832)

This commit is contained in:
tophf 2020-01-28 05:39:36 +03:00 committed by narcolepticinsomniac
parent 2b985a0a91
commit d3ee6d9498

View File

@ -823,11 +823,13 @@ onDOMready().then(() => {
if (numApplies === undefined && state.searchInApplies && state.numApplies < 0) { if (numApplies === undefined && state.searchInApplies && state.numApplies < 0) {
numApplies = 0; numApplies = 0;
const elements = state.find ? document.getElementsByClassName(APPLIES_VALUE_CLASS) : []; const elements = state.find ? document.getElementsByClassName(APPLIES_VALUE_CLASS) : [];
const {rx} = state;
for (const el of elements) { for (const el of elements) {
const value = el.value; const value = el.value;
if (state.rx) { if (rx) {
state.rx.lastIndex = 0; rx.lastIndex = 0;
while (state.rx.exec(value)) numApplies++; // preventing an infinite loop if matched an empty string and didn't advance
for (let m; (m = rx.exec(value)) && ++numApplies && rx.lastIndex > m.index;) { /* NOP */ }
} else { } else {
let i = -1; let i = -1;
while ((i = value.indexOf(state.find, i + 1)) >= 0) numApplies++; while ((i = value.indexOf(state.find, i + 1)) >= 0) numApplies++;