Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/thegeeklab/hugo-geekdoc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Kaussow <mail@geeklabor.de>2022-01-08 23:29:28 +0300
committerGitHub <noreply@github.com>2022-01-08 23:29:28 +0300
commitd89f0246eacb483988cb4e57f41232508e8d6421 (patch)
treec401e385b9657940dc991b6672c09cc0e2987252 /src
parenta78a8afb57413f6564e2e5a30ea37facece51923 (diff)
fix: replace ajv to avoid unsafe-eval (#269)
Diffstat (limited to 'src')
-rw-r--r--src/js/search.js15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/js/search.js b/src/js/search.js
index 3c9f584..6e93058 100644
--- a/src/js/search.js
+++ b/src/js/search.js
@@ -1,10 +1,8 @@
const { groupBy } = require("./groupBy")
const { FlexSearch } = require("flexsearch/dist/flexsearch.compact")
-const Ajv = require("ajv")
+const { Validator } = require("@cfworker/json-schema")
document.addEventListener("DOMContentLoaded", function (event) {
- const ajv = new Ajv()
-
const input = document.querySelector("#gdoc-search-input")
const results = document.querySelector("#gdoc-search-results")
@@ -23,17 +21,14 @@ document.addEventListener("DOMContentLoaded", function (event) {
},
additionalProperties: false
}
+ const validator = new Validator(configSchema)
getJson("/search/config.min.json", function (searchConfig) {
- const configValidate = ajv.compile(configSchema)
- const valid = configValidate(searchConfig)
+ const validationResult = validator.validate(searchConfig)
- if (!valid)
+ if (!validationResult.valid)
throw AggregateError(
- configValidate.errors.map(
- (err) =>
- new Error(["Validation error:", err.instancePath, err.keyword, err.message].join(" "))
- ),
+ validationResult.errors.map((err) => new Error("Validation error: " + err.error)),
"Schema validation failed"
)