From 41f0174362ad770963836ef797325ef41f773ee3 Mon Sep 17 00:00:00 2001 From: eight Date: Tue, 12 Sep 2017 02:46:37 +0800 Subject: [PATCH] Add: valid url --- js/usercss.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/js/usercss.js b/js/usercss.js index ae5d864c..7440044a 100644 --- a/js/usercss.js +++ b/js/usercss.js @@ -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]));