summaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-09-26 11:08:21 -0400
committerGitHub <noreply@github.com>2021-09-26 11:08:21 -0400
commitc15683d206c3bcfbaa1fa81f1c57836a34974e83 (patch)
treea409bf77fe6df6e4f5a217424ea4d687c7cfe958 /ext/js
parent9899727d7d53caed4c5b5e68176f7ed7f90a9438 (diff)
Ensure frequency values are always numbers (#1943)
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/language/translator.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js
index 1abf9f4e..056ff3a7 100644
--- a/ext/js/language/translator.js
+++ b/ext/js/language/translator.js
@@ -866,7 +866,7 @@ class Translator {
dictionaryIndex,
dictionaryPriority,
hasReading,
- frequency
+ this._convertFrequency(frequency)
));
}
}
@@ -920,7 +920,7 @@ class Translator {
dictionaryIndex,
dictionaryPriority,
character,
- data
+ this._convertFrequency(data)
));
}
break;
@@ -971,6 +971,18 @@ class Translator {
});
}
+ _convertFrequency(value) {
+ switch (typeof value) {
+ case 'number':
+ return value;
+ case 'string':
+ value = Number.parseFloat(value);
+ return Number.isFinite(value) ? value : 0;
+ default:
+ return 0;
+ }
+ }
+
// Helpers
_getNameBase(name) {