From ff900d31a4bf191b8b904320a0ddc0ddd792f192 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Tue, 28 Mar 2017 09:47:55 -0400 Subject: [PATCH] strip HRs before looking for title and copyright --- lib/licensee/content_helper.rb | 5 +++-- lib/licensee/matchers/copyright_matcher.rb | 1 + spec/licensee/content_helper_spec.rb | 11 ++++++----- spec/licensee/license_spec.rb | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/licensee/content_helper.rb b/lib/licensee/content_helper.rb index c3e0aa0..b1192b3 100644 --- a/lib/licensee/content_helper.rb +++ b/lib/licensee/content_helper.rb @@ -5,6 +5,7 @@ module Licensee module ContentHelper DIGEST = Digest::SHA1 END_OF_TERMS_REGEX = /^\s*end of terms and conditions\s*$/i + HR_REGEX = /^\s*[=-]{4,}/ ALT_TITLE_REGEX = { 'bsd-2-clause' => /bsd 2-clause( \"simplified\")? license/i, 'bsd-3-clause' => /bsd 3-clause( \"new\" or \"revised\")? license/i, @@ -55,6 +56,7 @@ module Licensee def content_without_title_and_version @content_without_title_and_version ||= begin string = content.strip + string = strip_hrs(string) string = strip_title(string) while string =~ title_regex strip_version(string).strip end @@ -68,7 +70,6 @@ module Licensee while string =~ Matchers::Copyright::REGEX string = strip_copyright(string) end - string = strip_hrs(string) string, _partition, _instructions = string.partition(END_OF_TERMS_REGEX) strip_whitespace(string) end @@ -101,7 +102,7 @@ module Licensee # Strip HRs from MPL def strip_hrs(string) - string.gsub(/[=-]{4,}/, '') + string.gsub HR_REGEX, '' end def strip_whitespace(string) diff --git a/lib/licensee/matchers/copyright_matcher.rb b/lib/licensee/matchers/copyright_matcher.rb index dcfd1a7..d260df5 100644 --- a/lib/licensee/matchers/copyright_matcher.rb +++ b/lib/licensee/matchers/copyright_matcher.rb @@ -1,4 +1,5 @@ # encoding: UTF-8 + module Licensee module Matchers class Copyright diff --git a/spec/licensee/content_helper_spec.rb b/spec/licensee/content_helper_spec.rb index e640920..7e6e33e 100644 --- a/spec/licensee/content_helper_spec.rb +++ b/spec/licensee/content_helper_spec.rb @@ -10,13 +10,14 @@ end RSpec.describe Licensee::ContentHelper do let(:content) do <<-EOS.freeze -The MIT License + The MIT License + =============== -Copyright 2016 Ben Balter + Copyright 2016 Ben Balter -The made -up license. ------------ + The made + up license. + ----------- EOS end subject { ContentHelperTestHelper.new(content) } diff --git a/spec/licensee/license_spec.rb b/spec/licensee/license_spec.rb index 2f286e1..8c0db03 100644 --- a/spec/licensee/license_spec.rb +++ b/spec/licensee/license_spec.rb @@ -35,7 +35,7 @@ RSpec.describe Licensee::License do end it "doesn't include hidden licenses" do - expect(licenses).to all satisfy { |license| !license.hidden? } + expect(licenses).to all(satisfy { |license| !license.hidden? }) end it 'includes featured licenses' do