aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-10-30 12:04:49 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2019-11-23 17:40:52 +0200
commitd19f447b80e286610a83114e2294a976a27adca5 (patch)
treebc832eacbfa8d67fdcf3d708e7cbe3a2e053c245 /ext/bg
parentc35a05cd62d43ff435c022a353de55510b020277 (diff)
fix stem length checking
Starting from the end and stopping at first match doesn't guarantee correctness. Starting from the beginning does.
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/api.js7
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;