From ddf7cd7fec894332cfe805c4880382d91f1cc853 Mon Sep 17 00:00:00 2001 From: Roman Seidelsohn Date: Sat, 15 Apr 2023 10:19:50 +0200 Subject: [PATCH] fix: Try to skip "license" URLs ending with image file name endings The checker recognizes ALL URLs as license URLs, which is plainly wrong. This is an experiment trying to improve the quality of detected URLs. --- lib/exitProcessOrWarnIfNeeded.js | 4 ++-- lib/getLicenseTitle.js | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/exitProcessOrWarnIfNeeded.js b/lib/exitProcessOrWarnIfNeeded.js index 8182a61..d3aab33 100644 --- a/lib/exitProcessOrWarnIfNeeded.js +++ b/lib/exitProcessOrWarnIfNeeded.js @@ -1,6 +1,6 @@ const usageMessage = require('./usageMessage'); -module.exports = function exitProcessOrWarnIfNeeded ({ unknownArgs, parsedArgs, hasFailingArg }) { +module.exports = function exitProcessOrWarnIfNeeded({ unknownArgs, parsedArgs, hasFailingArg }) { if (unknownArgs.length) { console.error(`license-checker-rseidelsohn@${require('../package.json').version}`, '\n'); console.error( @@ -35,4 +35,4 @@ module.exports = function exitProcessOrWarnIfNeeded ({ unknownArgs, parsedArgs, `Warning: The --${argName} argument takes semicolons as delimeters instead of commas (some license names can contain commas)`, ); } -} +}; diff --git a/lib/getLicenseTitle.js b/lib/getLicenseTitle.js index eaf6d12..0105455 100644 --- a/lib/getLicenseTitle.js +++ b/lib/getLicenseTitle.js @@ -21,6 +21,7 @@ const CC0_1_0 = /The\s+person\s+who\s+associated\s+a\s+work\s+with\s+this\s+deed\s+has\s+dedicated\s+the\s+work\s+to\s+the\s+public\s+domain\s+by\s+waiving\s+all\s+of\s+his\s+or\s+her\s+rights\s+to\s+the\s+work\s+worldwide\s+under\s+copyright\s+law,\s+including\s+all\s+related\s+and\s+neighboring\s+rights,\s+to\s+the\s+extent\s+allowed\s+by\s+law.\s+You\s+can\s+copy,\s+modify,\s+distribute\s+and\s+perform\s+the\s+work,\s+even\s+for\s+commercial\s+purposes,\s+all\s+without\s+asking\s+permission./i; // jshint ignore:line const PUBLIC_DOMAIN = /[Pp]ublic[\-_ ]*[Dd]omain/; const IS_URL = /(https?:\/\/[-a-zA-Z0-9\/.]*)/; +const DISCARD_URLS_ENDING_WITH = /(.svg|.gif|.png|.jpg|.jpeg)$/i; const IS_FILE_REFERENCE = /SEE LICENSE IN (.*)/i; const UNLICENSED = /UNLICENSED/i; @@ -160,7 +161,11 @@ module.exports = function getLicenseTitle(str = 'undefined') { match = IS_URL.exec(str) || IS_FILE_REFERENCE.exec(str); if (match) { - return 'Custom: ' + match[1]; + const matchedUrl = match[1]; + + if (!DISCARD_URLS_ENDING_WITH.test(matchedUrl)) { + return `Custom: ${matchedUrl}`; + } } else { return null; }