From 93578165ff522bca4f8ee031e43a363f7f2ecc01 Mon Sep 17 00:00:00 2001 From: Ruben Rodriguez Date: Wed, 31 Oct 2018 14:04:18 -0400 Subject: 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. --- main_background.js | 14 +++++++++++--- 1 file 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}".`]; -- cgit v1.2.3