Add: valid url

This commit is contained in:
eight 2017-09-12 02:46:37 +08:00
parent 3730a4e483
commit 41f0174362

View File

@ -263,12 +263,26 @@ var usercss = (function () {
// validate version
semverCompare(style.version, '0.0.0');
// validate URLs
validUrl(style.url);
validUrl(style.supportURL);
// validate vars
for (const key of Object.keys(style.vars)) {
validVar(style.vars[key]);
}
}
function validUrl(url) {
if (!url) {
return;
}
url = new URL(url);
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
throw new Error(`${url.protocol} is not a valid protocol`);
}
}
function validVar(va, value = 'default') {
if (va.type === 'select' && !va.select[va[value]]) {
throw new Error(chrome.i18n.getMessage('styleMetaErrorSelectMissingKey', va[value]));