aboutsummaryrefslogtreecommitdiff
path: root/ext/js/data/options-util.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-12-19 00:33:38 -0500
committerGitHub <noreply@github.com>2023-12-19 05:33:38 +0000
commit1ced9aafc00c10992bab8bd3f1b6b1397f05b7b9 (patch)
tree305bb2b3bfc7fc3b051ee1cd3d1c35f442af0de4 /ext/js/data/options-util.js
parent5f96276fda93dcad39f2165fd3c8d890aa5f9be5 (diff)
Make JSON.parse usage safer (#373)
* Make JSON.parse usage safer * Fix any type * Add readResponseJson * Use readResponseJson * Additional updates * Rename files * Add types
Diffstat (limited to 'ext/js/data/options-util.js')
-rw-r--r--ext/js/data/options-util.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js
index c3c0e685..a17763e9 100644
--- a/ext/js/data/options-util.js
+++ b/ext/js/data/options-util.js
@@ -17,6 +17,7 @@
*/
import {escapeRegExp, isObject} from '../core.js';
+import {parseJson, readResponseJson} from '../core/json.js';
import {TemplatePatcher} from '../templates/template-patcher.js';
import {JsonSchema} from './json-schema.js';
@@ -30,7 +31,8 @@ export class OptionsUtil {
/** */
async prepare() {
- const schema = /** @type {import('json-schema').Schema} */ (await this._fetchJson('/data/schemas/options-schema.json'));
+ /** @type {import('json-schema').Schema} */
+ const schema = await this._fetchJson('/data/schemas/options-schema.json');
this._optionsSchema = new JsonSchema(schema);
}
@@ -115,7 +117,7 @@ export class OptionsUtil {
}
});
});
- options = JSON.parse(optionsStr);
+ options = parseJson(optionsStr);
} catch (e) {
// NOP
}
@@ -477,12 +479,13 @@ export class OptionsUtil {
}
/**
+ * @template [T=unknown]
* @param {string} url
- * @returns {Promise<unknown>}
+ * @returns {Promise<T>}
*/
async _fetchJson(url) {
const response = await this._fetchGeneric(url);
- return await response.json();
+ return await readResponseJson(response);
}
/**