licensee 8.8.1 → 8.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ca170a986f774378d1a843c2d1f965108e02ea4
4
- data.tar.gz: fcf828df69ec47b230955311eedfa80e56ee7968
3
+ metadata.gz: 619ad8c9ec5567bab5810856457d95baeb3116be
4
+ data.tar.gz: d14fdefea813eb729cc4019d761c80b0c66825f2
5
5
  SHA512:
6
- metadata.gz: 307ef2552412239f196daa3892091d9bf814d6bf402871e97fdc8c222557d94145dc24799b3f0d0223f83c058618d09e78477ee1574c419e9b621e4038337634
7
- data.tar.gz: 808aae1ea2bb710fa968b741a3321a0716427100de2f5d439d1f675871ad38b32dcbf22a962cbe0d09da9890c91ed2630efbacc8487decfc2f00f49696d8bbf9
6
+ metadata.gz: ec4d52f35ceb0a363390cd8a6a9c0bd14d2a871e955ad99c528e7501f2935ef778c5739cbf3fe5fc62d8d2671713ef24f767494c495e14b0d3a2d817b0759e4c
7
+ data.tar.gz: 94e0d332a4d78d4a8344045d9db68ea7a3f871331a46c7c55bca084684505118da8e82715e1966be3bf4c3ba2ff8ef3620c0c5246fa9f62f45053aba1d6f7f82
@@ -43,14 +43,26 @@ module Licensee
43
43
  @hash ||= DIGEST.hexdigest content_normalized
44
44
  end
45
45
 
46
- # Content with copyright header and linebreaks removed
46
+ # Content with the title and version removed
47
+ # The first time should normally be the attribution line
48
+ # Used to dry up `content_normalized` but we need the case sensitive
49
+ # content with attribution first to detect attribuion in LicenseFile
50
+ def content_without_title_and_version
51
+ @content_without_title_and_version ||= begin
52
+ string = content.strip
53
+ string = strip_title(string) while string =~ title_regex
54
+ strip_version(string).strip
55
+ end
56
+ end
57
+
58
+ # Content without title, version, copyright, whitespace, or insturctions
47
59
  def content_normalized
48
60
  return unless content
49
61
  @content_normalized ||= begin
50
- string = content.downcase.strip
51
- string = strip_title(string) while string =~ title_regex
52
- string = strip_version(string)
53
- string = strip_copyright(string)
62
+ string = content_without_title_and_version.downcase
63
+ while string =~ Matchers::Copyright::REGEX
64
+ string = strip_copyright(string)
65
+ end
54
66
  string = strip_hrs(string)
55
67
  string, _partition, _instructions = string.partition(END_OF_TERMS_REGEX)
56
68
  strip_whitespace(string)
@@ -66,7 +78,7 @@ module Licensee
66
78
  end
67
79
 
68
80
  def title_regex
69
- /\A(the )?#{Regexp.union(license_names)}.*$/i
81
+ /\A\(?(the )?(#{Regexp.union(license_names).source}).*$/i
70
82
  end
71
83
 
72
84
  def strip_title(string)
@@ -78,7 +90,7 @@ module Licensee
78
90
  end
79
91
 
80
92
  def strip_copyright(string)
81
- string.gsub(/\A#{Matchers::Copyright::REGEX}$/i, '').strip
93
+ string.gsub(Matchers::Copyright::REGEX, '').strip
82
94
  end
83
95
 
84
96
  # Strip HRs from MPL
@@ -6,7 +6,7 @@ module Licensee
6
6
 
7
7
  # rubocop:disable Metrics/LineLength
8
8
  COPYRIGHT_SYMBOLS = Regexp.union([/copyright/i, /\(c\)/i, "\u00A9", "\xC2\xA9"])
9
- REGEX = /^\s*#{COPYRIGHT_SYMBOLS}.*$/i
9
+ REGEX = /\A\s*#{COPYRIGHT_SYMBOLS}.*$/i
10
10
  # rubocop:enable Metrics/LineLength
11
11
 
12
12
  def initialize(file)
@@ -40,8 +40,11 @@ module Licensee
40
40
  end
41
41
 
42
42
  def attribution
43
- matches = /^#{Matchers::Copyright::REGEX}$/i.match(content)
44
- matches[0].strip if matches
43
+ @attribution ||= begin
44
+ matches = Matchers::Copyright::REGEX
45
+ .match(content_without_title_and_version)
46
+ matches[0] if matches
47
+ end
45
48
  end
46
49
 
47
50
  # Is this file likely to result in a creative commons false positive?
@@ -1,3 +1,3 @@
1
1
  module Licensee
2
- VERSION = '8.8.1'.freeze
2
+ VERSION = '8.8.2'.freeze
3
3
  end
@@ -1,3 +1,4 @@
1
+ # Using a `.gemspec` extension here breaks the `gem release` command
1
2
  Gem::Specification.new do |gem|
2
3
  gem.name = "licensee-fixture-project"
3
4
  gem.license = 'mit'
@@ -2,7 +2,14 @@ class ContentHelperTestHelper
2
2
  include Licensee::ContentHelper
3
3
  attr_accessor :content
4
4
 
5
- DEFAULT_CONTENT = <<-EOS.freeze
5
+ def initialize(content = nil)
6
+ @content = content
7
+ end
8
+ end
9
+
10
+ RSpec.describe Licensee::ContentHelper do
11
+ let(:content) do
12
+ <<-EOS.freeze
6
13
  The MIT License
7
14
 
8
15
  Copyright 2016 Ben Balter
@@ -10,15 +17,9 @@ Copyright 2016 Ben Balter
10
17
  The made
11
18
  up license.
12
19
  -----------
13
- EOS
14
-
15
- def initialize(content = nil)
16
- @content = content || DEFAULT_CONTENT
20
+ EOS
17
21
  end
18
- end
19
-
20
- RSpec.describe Licensee::ContentHelper do
21
- subject { ContentHelperTestHelper.new }
22
+ subject { ContentHelperTestHelper.new(content) }
22
23
  let(:mit) { Licensee::License.find('mit') }
23
24
 
24
25
  it 'creates the wordset' do
@@ -74,13 +75,17 @@ RSpec.describe Licensee::ContentHelper do
74
75
 
75
76
  Licensee::License.all(hidden: true).each do |license|
76
77
  context license.name do
78
+ let(:stripped_content) { subject.content_without_title_and_version }
79
+
77
80
  it 'strips the title' do
78
81
  regex = /\A#{license.name_without_version}/i
79
82
  expect(license.content_normalized).to_not match(regex)
83
+ expect(stripped_content).to_not match(regex)
80
84
  end
81
85
 
82
86
  it 'strips the version' do
83
87
  expect(license.content_normalized).to_not match(/\Aversion/i)
88
+ expect(stripped_content).to_not match(/\Aversion/i)
84
89
  end
85
90
 
86
91
  it 'strips the copyright' do
@@ -102,5 +107,23 @@ RSpec.describe Licensee::ContentHelper do
102
107
  it 'normalize the content' do
103
108
  expect(normalized_content).to eql 'the made up license.'
104
109
  end
110
+
111
+ context 'a title in parenthesis' do
112
+ let(:content) { "(The MIT License)\n\nfoo" }
113
+
114
+ it 'strips the title' do
115
+ expect(normalized_content).to_not match('MIT')
116
+ expect(normalized_content).to eql('foo')
117
+ end
118
+ end
119
+
120
+ context 'multiple copyrights' do
121
+ let(:content) { "Copyright 2016 Ben Balter\nCopyright 2017 Bob\nFoo" }
122
+
123
+ it 'strips multiple copyrights' do
124
+ expect(normalized_content).to_not match('Ben')
125
+ expect(normalized_content).to eql('foo')
126
+ end
127
+ end
105
128
  end
106
129
  end
@@ -9,6 +9,14 @@ RSpec.describe Licensee::Project::LicenseFile do
9
9
  expect(subject.attribution).to eql('Copyright (c) 2016 Ben Balter')
10
10
  end
11
11
 
12
+ context "when there's a random copyright-like line" do
13
+ let(:content) { "Foo\nCopyright 2016 Ben Balter\nBar" }
14
+
15
+ it "doesn't match" do
16
+ expect(subject.attribution).to be_nil
17
+ end
18
+ end
19
+
12
20
  context 'with an non-UTF-8-encoded license' do
13
21
  let(:content) { "\x91License\x93".force_encoding('windows-1251') }
14
22
 
@@ -75,6 +75,22 @@
75
75
 
76
76
  context 'package manager detection' do
77
77
  let(:fixture) { 'gemspec' }
78
+
79
+ # Using a `.gemspec` extension in the fixture breaks `gem release`
80
+ before do
81
+ FileUtils.cp("#{path}/project._gemspec", "#{path}/project.gemspec")
82
+ if described_class == Licensee::GitProject
83
+ Dir.chdir path do
84
+ `git add project.gemspec`
85
+ `git commit -m 'add real gemspec'`
86
+ end
87
+ end
88
+ end
89
+
90
+ after do
91
+ FileUtils.rm("#{path}/project.gemspec")
92
+ end
93
+
78
94
  subject { described_class.new(path, detect_packages: true) }
79
95
 
80
96
  it 'returns the package file' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: licensee
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.8.1
4
+ version: 8.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-23 00:00:00.000000000 Z
11
+ date: 2017-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -130,8 +130,7 @@ files:
130
130
  - spec/fixtures/case-sensitive/LiCeNsE.TxT
131
131
  - spec/fixtures/cc-by-nc-sa/LICENSE
132
132
  - spec/fixtures/cc-by-nd/LICENSE
133
- - spec/fixtures/gemspec/lib/licensee-fixture-project/version.rb
134
- - spec/fixtures/gemspec/project.gemspec
133
+ - spec/fixtures/gemspec/project._gemspec
135
134
  - spec/fixtures/gpl3-without-instructions/LICENSE
136
135
  - spec/fixtures/lgpl/COPYING.lesser
137
136
  - spec/fixtures/lgpl/LICENSE