Commit cb2b2154 authored by Mickaël Menu's avatar Mickaël Menu Committed by Robert Knight

Fix exception in textMatchScore() when `text` is empty

parent 0de918ff
......@@ -54,7 +54,7 @@ function search(text, str, maxErrors) {
*/
function textMatchScore(text, str) {
/* istanbul ignore next - `scoreMatch` will never pass an empty string */
if (str.length === 0) {
if (str.length === 0 || text.length === 0) {
return 0.0;
}
const matches = search(text, str, str.length);
......@@ -116,7 +116,7 @@ export function matchQuote(text, quote, context = {}) {
const prefixScore = context.prefix
? textMatchScore(
text.slice(match.start - context.prefix.length, match.start),
text.slice(Math.max(0, match.start - context.prefix.length), match.start),
context.prefix
)
: 1.0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment