Skip to content

Commit 84dd999

Browse files
committed
fix: ensure translator paths are validated and correctly assigned
1 parent 25734e0 commit 84dd999

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

sources/contentScript.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ browser.runtime.onMessage.addListener(async (msg, _sender, _sendResponse) => {
6161
if (msg.type !== "runTranslators") return;
6262

6363
const translators = msg.translatorsInfo.map((info) => {
64+
const path = info.path;
65+
if (!path) {
66+
throw new Error(`Translator ${info.label} is missing a path`);
67+
}
6468
const translator = new Zotero.Translator(info);
6569
// Zotero expects the path to be under `file`
6670
translator.file = {
67-
path: translator.path,
71+
path: path,
6872
};
6973
return translator;
7074
});

sources/translateEngine.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ class TranslatorProvider {
7676

7777
const cache = { import: [], export: [], web: [], search: [] };
7878
for (const info of manifest) {
79+
const path = info.path;
80+
if (!path) {
81+
throw new Error(`Translator ${info.label} is missing a path`);
82+
}
7983
const translator = new Zotero.Translator(info);
8084
// Zotero expects the path to be under `file`
8185
translator.file = {
82-
path: translator.path,
86+
path: path,
8387
};
8488
const typeKeys = this._typeKey(translator.translatorType);
8589
for (const typeKey of typeKeys) {
@@ -161,8 +165,8 @@ class TranslatorProvider {
161165
*/
162166
async getCodeForTranslator(translator) {
163167
if (translator.code) return translator.code;
164-
if (translator.path) {
165-
const url = browser.runtime.getURL(translator.path);
168+
if (translator.file?.path) {
169+
const url = browser.runtime.getURL(translator.file.path);
166170
const response = await fetch(url);
167171
const code = await response.text();
168172
translator.code = code;

sources/translateWeb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export let TranslateWeb = {
9595
if (options.translators) {
9696
translate.setTranslator(options.translators);
9797
}
98-
return translate.getTranslators(true, !!options.translators);
98+
return await translate.getTranslators(true, !!options.translators);
9999
},
100100

101101
/**

0 commit comments

Comments
 (0)