aboutsummaryrefslogtreecommitdiff
path: root/bg
diff options
context:
space:
mode:
authorRuben Rodriguez <ruben@gnu.org>2018-10-03 22:23:39 +0000
committerRuben Rodriguez <ruben@gnu.org>2018-10-03 22:23:39 +0000
commit5461a48cbeac01d5f8bc31a10d11ff72a295c7d9 (patch)
tree3a6b571ac604ed2208f2a9b492de669e59d2f48f /bg
parentf881f1dbcd8c76685256f3701f25f916abda3e30 (diff)
parenteae399dfd0ade951e9bc87897247bcffffee614f (diff)
Merge #24 `Lenient WebLabels matching (by URL, by id, by name).`
Diffstat (limited to 'bg')
-rw-r--r--bg/ExternalLicenses.js45
1 files changed, 33 insertions, 12 deletions
diff --git a/bg/ExternalLicenses.js b/bg/ExternalLicenses.js
index 27d9223..33bcbf6 100644
--- a/bg/ExternalLicenses.js
+++ b/bg/ExternalLicenses.js
@@ -26,10 +26,28 @@
"use strict";
let licensesByLabel = new Map();
+let licensesByUrl = new Map();
{
let {licenses} = require("../license_definitions");
- for (let l of Object.values(licenses).filter(l => l.identifier)) {
- licensesByLabel.set(l.identifier, l);
+ let mapByLabel = (label, license) => licensesByLabel.set(label.toUpperCase(), license);
+ for (let [id, l] of Object.entries(licenses)) {
+ let {identifier, canonicalUrl, licenseName} = l;
+ if (identifier) {
+ mapByLabel(identifier, l);
+ } else {
+ l.identifier = id;
+ }
+ if (id !== identifier) {
+ mapByLabel(id, l);
+ }
+ if (licenseName) {
+ mapByLabel(licenseName, l);
+ }
+ if (Array.isArray(canonicalUrl)) {
+ for (let url of canonicalUrl) {
+ licensesByUrl.set(url, l);
+ }
+ }
}
}
@@ -55,23 +73,26 @@ var ExternalLicenses = {
return null;
}
scriptInfo.licenses = new Set();
- scriptInfo.allFree = true;
scriptInfo.toString = function() {
let licenseIds = [...this.licenses].map(l => l.identifier).sort().join(", ");
return licenseIds
- ? (this.allFree ? `Free license${this.licenses.length > 1 ? "s" : ""} (${licenseIds})`
- : `Mixed free (${licenseIds}) and unknown licenses`)
+ ? `Free license${this.licenses.size > 1 ? "s" : ""} (${licenseIds})`
: "Unknown license(s)";
}
-
- for (let {label} of scriptInfo.licenseLinks) {
- if (licensesByLabel.has(label)) {
- scriptInfo.licenses.add(licensesByLabel.get(label));
- } else {
- scriptInfo.allFree = false;
- break;
+ let match = (map, key) => {
+ if (map.has(key)) {
+ scriptInfo.licenses.add(map.get(key));
+ return true;
}
+ return false;
+ };
+
+ for (let {label, url} of scriptInfo.licenseLinks) {
+ match(licensesByLabel, label = label.trim().toUpperCase()) ||
+ match(licensesByUrl, url) ||
+ match(licensesByLabel, label.replace(/^GNU-|-(?:OR-LATER|ONLY)$/, ''));
}
+ scriptInfo.free = scriptInfo.licenses.size > 0;
return scriptInfo;
},