aboutsummaryrefslogtreecommitdiff
path: root/main_background.js
diff options
context:
space:
mode:
authorhackademix <giorgio@maone.net>2018-09-26 23:42:17 +0200
committerhackademix <giorgio@maone.net>2018-09-26 23:42:17 +0200
commit9adcb36524c91da63e99ec747707ef10f57e4171 (patch)
tree8b540edff0bb1862e7830435b4511f3546a9f40b /main_background.js
parent564f2eb266bda6c947aae303a449406e7d40f190 (diff)
More meaningful license tag validation messages.
Diffstat (limited to 'main_background.js')
-rw-r--r--main_background.js33
1 files changed, 16 insertions, 17 deletions
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]+"'<br>"];
+ 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);