aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-04-05 21:02:52 +1000
committerYuchen Pei <hi@ypei.me>2022-04-07 12:18:45 +1000
commitd933d6dec67395c0d1ee899d88c718ee9fe3a30d (patch)
tree9bec8f10a288c5a3faadee6cf2cccaf555773481
parentae25ad78906179e1448ff7d97957810e2be40206 (diff)
updating validation of @license comments to check magnet / url only.
- this is the desired behaviour, see also <https://lists.gnu.org/archive/html/help-librejs/2021-12/msg00000.html> - also changed some unmuated identifiers from let to const
-rw-r--r--main_background.js25
1 files changed, 10 insertions, 15 deletions
diff --git a/main_background.js b/main_background.js
index 0d52308..7b47c7b 100644
--- a/main_background.js
+++ b/main_background.js
@@ -615,14 +615,9 @@ function validateLicense(matches) {
return [false, "Malformed or unrecognized license tag."];
}
- let [all, tag, first, second] = matches;
+ const [all, first] = [matches[0], matches[2]];
for (let key in licenses) {
- // Match by id on first or second parameter, ignoring case
- if (key.toLowerCase() === first.toLowerCase() ||
- key.toLowerCase() === second.toLowerCase()) {
- return [true, `Recognized license: "${licenses[key]['Name']}" `];
- }
// Match by link on first parameter (legacy)
if (licenses[key]["Magnet link"] === first.replace("&amp;", "&") ||
licenses[key]["URL"] === first.replace("&amp;", "&") ||
@@ -647,7 +642,7 @@ function validateLicense(matches) {
*/
function license_read(scriptSrc, name, external = false) {
- let license = legacy_license_lib.check(scriptSrc);
+ const license = legacy_license_lib.check(scriptSrc);
if (license) {
return [true, scriptSrc, `Licensed under: ${license}`];
}
@@ -665,7 +660,7 @@ function license_read(scriptSrc, name, external = false) {
if (!s.trim()) {
return true; // empty, ignore it
}
- let [trivial, message] = external ?
+ const [trivial, message] = external ?
[false, "External script with no known license"]
: evaluate(s, name);
if (trivial) {
@@ -683,13 +678,13 @@ function license_read(scriptSrc, name, external = false) {
}
while (uneditedSrc) {
- let openingMatch = /\/[\/\*]\s*?(@license)\s+(\S+)\s+(\S+)\s*$/mi.exec(uneditedSrc);
+ const openingMatch = /\/[\/\*]\s*?(@license)\s+(\S+)\s+(\S+).*$/mi.exec(uneditedSrc);
if (!openingMatch) { // no license found, check for triviality
checkTriviality(uneditedSrc);
break;
}
- let openingIndex = openingMatch.index;
+ const openingIndex = openingMatch.index;
if (openingIndex) {
// let's check the triviality of the code before the license tag, if any
checkTriviality(uneditedSrc.substring(0, openingIndex));
@@ -697,19 +692,19 @@ function license_read(scriptSrc, name, external = false) {
// let's check the actual license
uneditedSrc = uneditedSrc.substring(openingIndex);
- let closureMatch = /\/([*/])\s*@license-end\b[^*/\n]*/i.exec(uneditedSrc);
+ const closureMatch = /\/([*/])\s*@license-end\b[^*/\n]*/i.exec(uneditedSrc);
if (!closureMatch) {
- let msg = "ERROR: @license with no @license-end";
+ const msg = "ERROR: @license with no @license-end";
return [false, `\n/*\n ${msg} \n*/\n`, msg];
}
- let closureEndIndex = closureMatch.index + closureMatch[0].length;
- let commentEndOffset = uneditedSrc.substring(closureEndIndex).indexOf(closureMatch[1] === "*" ? "*/" : "\n");
+ const closureEndIndex = closureMatch.index + closureMatch[0].length;
+ const commentEndOffset = uneditedSrc.substring(closureEndIndex).indexOf(closureMatch[1] === "*" ? "*/" : "\n");
if (commentEndOffset !== -1) {
closureEndIndex += commentEndOffset;
}
- let [licenseOK, message] = validateLicense(openingMatch);
+ const [licenseOK, message] = validateLicense(openingMatch);
if (licenseOK) {
editedSrc += uneditedSrc.substr(0, closureEndIndex);
partsAccepted = true;