diff options
| -rw-r--r-- | ext/bg/js/api.js | 7 | 
1 files 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; |