Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Exact matcher to detect OFL with a reserved font name #546

Merged
merged 2 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/licensee/matchers/copyright.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class Copyright < Licensee::Matchers::Matcher
attr_reader :file

COPYRIGHT_SYMBOLS = Regexp.union([/copyright/i, /\(c\)/i, "\u00A9", "\xC2\xA9"])
REGEX = /#{ContentHelper::START_REGEX}([_*\-\s]*#{COPYRIGHT_SYMBOLS}.*$)+$/i.freeze
MAIN_LINE_REGEX = /[_*\-\s]*#{COPYRIGHT_SYMBOLS}.*$/i.freeze
OPTIONAL_LINE_REGEX = /[_*\-\s]*with Reserved Font Name.*$/i.freeze
REGEX = /#{ContentHelper::START_REGEX}(#{MAIN_LINE_REGEX}#{OPTIONAL_LINE_REGEX}*)+$/i.freeze
def match
# NOTE: must use content, and not content_normalized here
Licensee::License.find('no-license') if /#{REGEX}+\z/io.match?(file.content.strip)
Expand Down
15 changes: 12 additions & 3 deletions spec/licensee/matchers/copyright_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
'UTF-8 Encoded' => 'Copyright (c) 2010-2014 Simon Hürlimann',
'Comma-separated date' => 'Copyright (c) 2003, 2004 Ben Balter',
'Hyphen-separated date' => 'Copyright (c) 2003-2004 Ben Balter',
'ASCII-8BIT encoded' => "Copyright \xC2\xA92015 Ben Balter`",
'ASCII-8BIT encoded' => "Copyright \xC2\xA92015 Ben Balter`"
.dup.force_encoding('ASCII-8BIT'),
'No year' => 'Copyright Ben Balter',
'Multiline' => "Copyright Ben Balter\nCopyright Another Entity"
.dup.force_encoding('ASCII-8BIT')
'Multiline' => "Copyright Ben Balter\nCopyright Another Entity",
'OFL font name' => "Copyright (c) 2016, Ben Balter,\nwith Reserved Font Name \"Ben's Font\"."
}.each do |description, notice|
context "with a #{description} notice" do
let(:content) { notice }
Expand All @@ -41,6 +42,14 @@
end
end

context 'with arbitrary additional notice line' do
let(:content) { "(c) Ben Balter\nwith foo bar baz" }

it "doesn't match" do
expect(subject.match).to be_nil
end
end

context 'with a license with a copyright notice' do
let(:content) { sub_copyright_info(mit) }

Expand Down