From 9adcb36524c91da63e99ec747707ef10f57e4171 Mon Sep 17 00:00:00 2001 From: hackademix Date: Wed, 26 Sep 2018 23:42:17 +0200 Subject: More meaningful license tag validation messages. --- main_background.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'main_background.js') diff --git a/main_background.js b/main_background.js index a145cc5..59642c2 100644 --- a/main_background.js +++ b/main_background.js @@ -643,20 +643,19 @@ function evaluate(script,name){ -function license_valid(matches){ - if(matches.length != 4){ - return [false, "malformed or unrecognized license tag"]; +function validateLicense(matches) { + if (!(Array.isArray(matches) && matches.length === 4)){ + return [false, "Malformed or unrecognized license tag."]; } - if(matches[1] != "@license"){ - return [false, "malformed or unrecognized license tag"]; + let [all, tag, link, id] = matches; + let license = licenses[id]; + if(!license){ + return [false, `Unrecognized license "${id}"`]; } - if(licenses[matches[3]] === undefined){ - return [false, "malformed or unrecognized license tag"]; + if(license["Magnet link"] != link){ + return [false, `License magnet link does not match for "${id}".`]; } - if(licenses[matches[3]]["Magnet link"] != matches[2]){ - return [false, "malformed or unrecognized license tag"]; - } - return [true,"Recognized license as '"+matches[3]+"'
"]; + return [true, `Recognized license: "${id}".`]; } /** * @@ -743,13 +742,13 @@ function license_read(script_src, name, external = false){ return [false,"\n/*\n ERROR: @license with no @license-end \n*/\n","ERROR: @license with no @license-end"]; } var endtag_end_index = matches_end["index"]+matches_end[0].length; - var license_res = license_valid(matches); - if(license_res[0] == true){ - edited_src = edited_src + unedited_src.substr(0,endtag_end_index); - reason_text += "\n" + license_res[1]; + let [licenseOK, licenseMessage] = validateLicense(matches); + if(licenseOK) { + edited_src += unedited_src.substr(0, endtag_end_index); + reason_text += `\n${licenseMessage}`; } else{ - edited_src = edited_src + "\n/*\n"+license_res[1]+"\n*/\n"; - reason_text += "\n" + license_res[1]; + edited_src += `\n/*\n${licenseMessage}\n*/\n`; + reason_text += `\n${licenseMessage}`; } // trim off everything we just evaluated unedited_src = unedited_src.substr(endtag_end_index,unedited_src.length); -- cgit v1.2.3