class Licensee::Matchers::NuGet

Constants

APACHE_REGEX
LICENSE_REGEX

While we could parse the nuspec file, prefer a lenient regex for speed and security. Moar parsing moar problems.

LICENSE_URL_REGEX
NUGET_REGEX
OPENSOURCE_REGEX
SPDX_REGEX

Private Instance Methods

license_from_first_capture(url, pattern) click to toggle source
# File lib/licensee/matchers/nuget.rb, line 21
def license_from_first_capture(url, pattern)
  match = url.match(pattern)
  match[1].downcase if match && match[1]
end
license_from_url(url) click to toggle source
# File lib/licensee/matchers/nuget.rb, line 26
def license_from_url(url)
  license_from_first_capture(url, NUGET_REGEX) ||
    license_from_first_capture(url, OPENSOURCE_REGEX) ||
    license_from_first_capture(url, SPDX_REGEX) ||
    license_from_first_capture(url, APACHE_REGEX)&.gsub('license', 'apache')
end
license_property() click to toggle source
# File lib/licensee/matchers/nuget.rb, line 33
def license_property
  # Prefer the explicit <license type="expression"> element
  match = @file.content.match LICENSE_REGEX
  return match[1].downcase if match && match[1]

  url_match = @file.content.match LICENSE_URL_REGEX
  license_from_url(url_match[1]) if url_match && url_match[1]
end