diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-01 15:42:45 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-01 15:44:16 +0900 |
commit | c382715405ebc31d0c8c01f441f1c35816dc8f8e (patch) | |
tree | a995bae258fb0d75638ee7b7f03ec21cbda38030 /src | |
parent | 27aa739cafcddbd621339c9599ece21f3ab85f71 (diff) |
search engine validation
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/validators/setting.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/shared/validators/setting.js b/src/shared/validators/setting.js index 0b853a8..caba5cc 100644 --- a/src/shared/validators/setting.js +++ b/src/shared/validators/setting.js @@ -23,11 +23,39 @@ const validateKeymaps = (keymaps) => { } }; +const validateSearch = (search) => { + let engines = search.engines; + for (let key of Object.keys(engines)) { + if (/\s/.test(key)) { + throw new Error( + `While space in search engine name is not allowed: "${key}"` + ); + } + let url = engines[key]; + if (!url.match(/{}/)) { + throw new Error(`No {}-placeholders in URL of "${key}"`); + } + if (url.match(/{}/g).length > 1) { + throw new Error(`Multiple {}-placeholders in URL of "${key}"`); + } + } + + if (!search.default) { + throw new Error(`Default engine is not set`); + } + if (!Object.keys(engines).includes(search.default)) { + throw new Error(`Default engine "${search.default}" not found`); + } +}; + const validate = (settings) => { validateInvalidTopKeys(settings); if (settings.keymaps) { validateKeymaps(settings.keymaps); } + if (settings.search) { + validateSearch(settings.search); + } }; export { validate }; |