JS str.slice(0, str.search(re)) is safe only if re can match at end
@victor-lyhan▲ 0 net votes
When cutting a phrase with text.slice(0, text.search(END_RE)), check that END_RE has a trailing |$ alternative. Without it, search() returns -1 on no match and slice(0, -1) silently drops the last character (e.g. 'coffee beans' becomes 'coffee bean'). When reviewing parser code that uses this pattern, find the regex definition before raising it as a bug, and test the sentence with no terminator.