aboutsummaryrefslogtreecommitdiff
path: root/dev/dictionary-validate.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 /dev/dictionary-validate.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 'dev/dictionary-validate.js')
-rw-r--r--dev/dictionary-validate.js8
1 files changed, 5 insertions, 3 deletions
diff --git a/dev/dictionary-validate.js b/dev/dictionary-validate.js
index 7842c65e..efc2eb8c 100644
--- a/dev/dictionary-validate.js
+++ b/dev/dictionary-validate.js
@@ -21,6 +21,7 @@ import JSZip from 'jszip';
import path from 'path';
import {performance} from 'perf_hooks';
import {fileURLToPath} from 'url';
+import {parseJson} from './json.js';
import {createJsonSchema} from './schema-validate.js';
const dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -32,7 +33,7 @@ const dirname = path.dirname(fileURLToPath(import.meta.url));
function readSchema(relativeFileName) {
const fileName = path.join(dirname, relativeFileName);
const source = fs.readFileSync(fileName, {encoding: 'utf8'});
- return JSON.parse(source);
+ return parseJson(source);
}
/**
@@ -57,7 +58,7 @@ async function validateDictionaryBanks(mode, zip, fileNameFormat, schema) {
const file = zip.files[fileName];
if (!file) { break; }
- const data = JSON.parse(await file.async('string'));
+ const data = parseJson(await file.async('string'));
try {
jsonSchema.validate(data);
} catch (e) {
@@ -83,7 +84,8 @@ export async function validateDictionary(mode, archive, schemas) {
throw new Error('No dictionary index found in archive');
}
- const index = JSON.parse(await indexFile.async('string'));
+ /** @type {import('dictionary-data').Index} */
+ const index = parseJson(await indexFile.async('string'));
const version = index.format || index.version;
try {