aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language/translator.js
diff options
context:
space:
mode:
authorStefanVukovic99 <stefanvukovic44@gmail.com>2024-05-14 21:26:53 +0200
committerGitHub <noreply@github.com>2024-05-14 19:26:53 +0000
commitd6e49f51d7514ac8436a978df72afbdf6e723b0f (patch)
tree16de485507355c53337135ada592a89affac18af /ext/js/language/translator.js
parent266c8c3a3f0d6f8c39832bfdc0cc88b88c2b710b (diff)
fix search resolution infinite loop (#938)
Diffstat (limited to 'ext/js/language/translator.js')
-rw-r--r--ext/js/language/translator.js24
1 files changed, 10 insertions, 14 deletions
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js
index 0d26b2f0..31fc6d81 100644
--- a/ext/js/language/translator.js
+++ b/ext/js/language/translator.js
@@ -461,12 +461,10 @@ export class Translator {
const sourceCache = new Map(); // For reusing text processors' outputs
for (
- let i = text.length;
- i > 0;
- i = this._getNextSubstringLength(options.searchResolution, i, text)
+ let rawSource = text;
+ rawSource.length > 0;
+ rawSource = this._getNextSubstring(options.searchResolution, rawSource)
) {
- const rawSource = text.substring(0, i);
-
for (const preprocessorVariant of preprocessorVariants) {
let source = rawSource;
@@ -534,16 +532,14 @@ export class Translator {
/**
* @param {string} searchResolution
- * @param {number} currentLength
- * @param {string} source
- * @returns {number}
+ * @param {string} currentString
+ * @returns {string}
*/
- _getNextSubstringLength(searchResolution, currentLength, source) {
- return (
- searchResolution === 'word' ?
- source.search(/[^\p{Letter}][\p{Letter}\p{Number}]*$/u) :
- currentLength - 1
- );
+ _getNextSubstring(searchResolution, currentString) {
+ const nextSubstringLength = searchResolution === 'word' ?
+ currentString.search(/[^\p{Letter}][\p{Letter}\p{Number}]*$/u) :
+ currentString.length - 1;
+ return currentString.substring(0, nextSubstringLength);
}
/**