aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Rodriguez <ruben@fsf.org>2018-10-31 14:04:18 -0400
committerRuben Rodriguez <ruben@fsf.org>2018-10-31 14:04:18 -0400
commit93578165ff522bca4f8ee031e43a363f7f2ecc01 (patch)
tree563640cf916633330f7bedf28632009953672251
parent8c1bd035a207836c337b3169fe7b7316668c68fd (diff)
More generalized license matching
* Allow for length >= 4 since somebody may write "GPL2.0 or later" or something like that. It should still work if the tag follows the new recommendations. * Match the link to the URL or Magnet Link fields in the licenses table. Currently it matches only by id, and the link field is only used to fail the match if the link is not the same as in the table.
-rw-r--r--main_background.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/main_background.js b/main_background.js
index 8848956..0b6e407 100644
--- a/main_background.js
+++ b/main_background.js
@@ -616,15 +616,23 @@ function evaluate(script,name){
function validateLicense(matches) {
- if (!(Array.isArray(matches) && matches.length === 4)){
+ if (!(Array.isArray(matches) && matches.length >= 4)){
return [false, "Malformed or unrecognized license tag."];
}
let [all, tag, link, id] = matches;
- let license = licenses[id];
+ let license = null;
+ if (licenses[id])
+ license = licenses[id];
+ for (let key in licenses){
+ if (licenses[key]["Magnet link"] === link)
+ license = licenses[key];
+ if (licenses[key]["URL"] === link)
+ license = licenses[key];
+ }
if(!license){
return [false, `Unrecognized license "${id}"`];
}
- if(license["Magnet link"] != link){
+ if (!(license["Magnet link"] === link || license["URL"] === link)){
return [false, `License magnet link does not match for "${id}".`];
}
return [true, `Recognized license: "${id}".`];