Merge branch 'zj/gitlab-ce-copying-file-seen-as-licence'
This commit is contained in:
commit
cd97dba2a9
|
@ -42,6 +42,7 @@ v 8.3.0 (unreleased)
|
|||
- Fix sidebar tooltips when collapsed
|
||||
- Prevent possible XSS attack with award-emoji
|
||||
- Upgraded Sidekiq to 4.x
|
||||
- Accept COPYING,COPYING.lesser, and licence as license file (Zeger-Jan van de Weg)
|
||||
|
||||
v 8.2.3
|
||||
- Fix application settings cache not expiring after changes (Stan Hu)
|
||||
|
|
|
@ -271,9 +271,25 @@ class Repository
|
|||
|
||||
def license
|
||||
cache.fetch(:license) do
|
||||
tree(:head).blobs.find do |file|
|
||||
file.name =~ /\Alicense/i
|
||||
licenses = tree(:head).blobs.find_all do |file|
|
||||
file.name =~ /\A(copying|license|licence)/i
|
||||
end
|
||||
|
||||
preferences = [
|
||||
/\Alicen[sc]e\z/i, # LICENSE, LICENCE
|
||||
/\Alicen[sc]e\./i, # LICENSE.md, LICENSE.txt
|
||||
/\Acopying\z/i, # COPYING
|
||||
/\Acopying\.(?!lesser)/i, # COPYING.txt
|
||||
/Acopying.lesser/i # COPYING.LESSER
|
||||
]
|
||||
|
||||
license = nil
|
||||
preferences.each do |r|
|
||||
license = licenses.find { |l| l.name =~ r }
|
||||
break if license
|
||||
end
|
||||
|
||||
license
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -103,6 +103,26 @@ describe Repository, models: true do
|
|||
|
||||
end
|
||||
|
||||
describe "#license" do
|
||||
before do
|
||||
repository.send(:cache).expire(:license)
|
||||
TestBlob = Struct.new(:name)
|
||||
end
|
||||
|
||||
it 'test selection preference' do
|
||||
files = [TestBlob.new('file'), TestBlob.new('license'), TestBlob.new('copying')]
|
||||
expect(repository.tree).to receive(:blobs).and_return(files)
|
||||
|
||||
expect(repository.license.name).to eq('license')
|
||||
end
|
||||
|
||||
it 'also accepts licence instead of license' do
|
||||
expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('licence')])
|
||||
|
||||
expect(repository.license.name).to eq('licence')
|
||||
end
|
||||
end
|
||||
|
||||
describe :add_branch do
|
||||
context 'when pre hooks were successful' do
|
||||
it 'should run without errors' do
|
||||
|
@ -199,5 +219,4 @@ describe Repository, models: true do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue