aboutsummaryrefslogtreecommitdiff
path: root/main_background.js
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-04-06 13:08:54 +1000
committerYuchen Pei <hi@ypei.me>2022-04-07 12:18:45 +1000
commit76fd7f798ada63f5505c783646a9b21ad0e7da21 (patch)
treee65a8baa4862c62201b9510f76d6c82aef74ac32 /main_background.js
parent3276ce9a286fa77d2b4859ff29cda4ce678134cd (diff)
Making license_definition.js single source of truth for licenses
- Removed licenses.json - cleaned up license_definition.js a bit
Diffstat (limited to 'main_background.js')
-rw-r--r--main_background.js25
1 files changed, 13 insertions, 12 deletions
diff --git a/main_background.js b/main_background.js
index 7b47c7b..0bfb33c 100644
--- a/main_background.js
+++ b/main_background.js
@@ -64,7 +64,7 @@ function dbg_print(a, b) {
- "// @license [magnet link] [identifier]" then "// @license-end" (may also use /* comments)
- Automatic whitelist: (http://bzr.savannah.gnu.org/lh/librejs/dev/annotate/head:/data/script_libraries/script-libraries.json_
*/
-var licenses = require("./licenses.json").licenses;
+const { licenses } = require("./license_definitions");
// These are objects that it will search for in an initial regex pass over non-free scripts.
var reserved_objects = [
@@ -615,14 +615,14 @@ function validateLicense(matches) {
return [false, "Malformed or unrecognized license tag."];
}
- const [all, first] = [matches[0], matches[2]];
+ const [all, first] = [matches[0], matches[2].replace("&amp;", "&")];
- for (let key in licenses) {
+ for (const key in licenses) {
// Match by link on first parameter (legacy)
- if (licenses[key]["Magnet link"] === first.replace("&amp;", "&") ||
- licenses[key]["URL"] === first.replace("&amp;", "&") ||
- licenses[key]["URL"].replace("http://", "https://") === first.replace("&amp;", "&")) {
- return [true, `Recognized license: "${licenses[key]['Name']}".`];
+ for (const url of licenses[key].canonicalUrl) {
+ if (first === url || first === url.replace("^http://", "https://")) {
+ return [true, `Recognized license: "${licenses[key].licenseName}".`];
+ }
}
}
return [false, `Unrecognized license tag: "${all}"`];
@@ -1026,12 +1026,13 @@ function read_metadata(meta_element) {
parts[0] = parts[0].replace(/&amp;/g, '&');
try {
- if (licenses[parts[1]]["Magnet link"] == parts[0]) {
- return true;
- } else {
- console.log("invalid (doesn't match licenses)");
- return false;
+ for (const url of licenses[part[1]].canonicalUrl) {
+ if (url.startsWith("magnet:") && url == parts[0]) {
+ return true;
+ }
}
+ console.log("invalid (doesn't match licenses)");
+ return false;
} catch (error) {
console.log("invalid (threw error, key didn't exist)");
return false;