Skip to content

Commit

Permalink
Merge pull request #546 from saltcandy123/add-copyright-fontname-regex
Browse files Browse the repository at this point in the history
Enable Exact matcher to detect OFL with a reserved font name
  • Loading branch information
mlinksva committed Apr 7, 2022
2 parents f17315a + 654d84b commit ba9913e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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

0 comments on commit ba9913e

Please sign in to comment.