From d19f447b80e286610a83114e2294a976a27adca5 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Wed, 30 Oct 2019 12:04:49 +0200 Subject: [PATCH] fix stem length checking Starting from the end and stopping at first match doesn't guarantee correctness. Starting from the beginning does. --- ext/bg/js/api.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 064903ca..174a439e 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -90,9 +90,10 @@ async function apiTextParse(text, optionsContext) { definitions = dictTermsSort(definitions); const {expression, source, reading} = definitions[0]; - let stemLength = source.length; - while (source[stemLength - 1] !== expression[stemLength - 1]) { - --stemLength; + let stemLength = 0; + const shortest = Math.min(source.length, expression.length); + while (stemLength < shortest && source[stemLength] === expression[stemLength]) { + ++stemLength; } const offset = source.length - stemLength;