Skip to content

Commit

Permalink
Changed approach to find license text files to be case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Schiebel committed Jan 25, 2023
1 parent 0d44a40 commit d0c1d1c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/licensetexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.

import { Enums, Models } from '@cyclonedx/cyclonedx-library'
import * as fs from 'fs'
import * as minimatch from 'minimatch'
import { join } from 'path'

import { PropertyNames } from './properties'
Expand Down Expand Up @@ -50,13 +51,13 @@ function searchLicenseSources (pkgPath: string, licenseName: string): Map<string
if (pkgPath.length < 1) {
return licenseFilenamesWType
}
const typicalFilenames = ['LICENSE', 'License', 'license', 'LICENCE', 'Licence', 'licence', 'NOTICE', 'Notice', 'notice']
const typicalFilenames = ['license', 'licence', 'notice', 'unlicense', 'unlicence']
const licenseContentTypes = { 'text/plain': '', 'text/txt': '.txt', 'text/markdown': '.md', 'text/xml': '.xml' }
const potentialFilenames = fs.readdirSync(pkgPath)
for (const typicalFilename of typicalFilenames) {
for (const filenameVariant of [typicalFilename, typicalFilename + '.' + licenseName, typicalFilename + '-' + licenseName]) {
for (const [licenseContentType, fileExtension] of Object.entries(licenseContentTypes)) {
const filename = join(pkgPath, filenameVariant + fileExtension)
if (fs.existsSync(filename) && fs.realpathSync.native(filename).endsWith(filename)) { // needed to fix case-insensitivity on Windows
for (const filename of minimatch.match(potentialFilenames, filenameVariant + fileExtension, { nocase: true, noglobstar: true, noext: true })) {
licenseFilenamesWType.set(filename, licenseContentType)
}
}
Expand Down

0 comments on commit d0c1d1c

Please sign in to comment.