Skip to content

Commit

Permalink
fix: Try to skip "license" URLs ending with image file name endings
Browse files Browse the repository at this point in the history
The checker recognizes ALL URLs as license URLs, which is plainly wrong.
This is an experiment trying to improve the quality of detected URLs.
  • Loading branch information
RSeidelsohn committed Apr 15, 2023
1 parent 2e7d98c commit ddf7cd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/exitProcessOrWarnIfNeeded.js
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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)`,
);
}
}
};
7 changes: 6 additions & 1 deletion lib/getLicenseTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit ddf7cd7

Please sign in to comment.