Merge branch 'sh-cleanup-crlf-gitmodules' into 'master'

Handle CR-LFs properly in .gitmodules file

Closes #2262

See merge request gitlab-org/gitlab-ce!18117
This commit is contained in:
Douwe Maan 2018-04-02 14:25:35 +00:00
commit 1c40f18f02
2 changed files with 5 additions and 2 deletions

View File

@ -46,6 +46,8 @@ module Gitlab
iterator = State.new
@content.split("\n").each_with_object(iterator) do |text, iterator|
text.chomp!
next if text =~ /^\s*#/
if text =~ /\A\[submodule "(?<name>[^"]+)"\]\z/
@ -55,7 +57,7 @@ module Gitlab
next unless text =~ /\A\s*(?<key>\w+)\s*=\s*(?<value>.*)\z/
value = $~[:value].chomp
value = $~[:value]
iterator.set_attribute($~[:key], value)
end
end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::Git::GitmodulesParser do
it 'should parse a .gitmodules file correctly' do
parser = described_class.new(<<-'GITMODULES'.strip_heredoc)
data = <<~GITMODULES
[submodule "vendor/libgit2"]
path = vendor/libgit2
[submodule "vendor/libgit2"]
@ -16,6 +16,7 @@ describe Gitlab::Git::GitmodulesParser do
url = https://example.com/another/project
GITMODULES
parser = described_class.new(data.gsub("\n", "\r\n"))
modules = parser.parse
expect(modules).to eq({