Commit 6fd1d07c authored by Stan Hu's avatar Stan Hu

Handle CR-LFs properly in .gitmodules file

Any submodule lines that had a CR-LF ending would be ignored by the parser.

Closes gitlab-org/gitlab-ce#2262
parent d2ad0bcc
...@@ -46,6 +46,8 @@ module Gitlab ...@@ -46,6 +46,8 @@ module Gitlab
iterator = State.new iterator = State.new
@content.split("\n").each_with_object(iterator) do |text, iterator| @content.split("\n").each_with_object(iterator) do |text, iterator|
text.chomp!
next if text =~ /^\s*#/ next if text =~ /^\s*#/
if text =~ /\A\[submodule "(?<name>[^"]+)"\]\z/ if text =~ /\A\[submodule "(?<name>[^"]+)"\]\z/
...@@ -55,7 +57,7 @@ module Gitlab ...@@ -55,7 +57,7 @@ module Gitlab
next unless text =~ /\A\s*(?<key>\w+)\s*=\s*(?<value>.*)\z/ next unless text =~ /\A\s*(?<key>\w+)\s*=\s*(?<value>.*)\z/
value = $~[:value].chomp value = $~[:value]
iterator.set_attribute($~[:key], value) iterator.set_attribute($~[:key], value)
end end
end end
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::Git::GitmodulesParser do describe Gitlab::Git::GitmodulesParser do
it 'should parse a .gitmodules file correctly' do it 'should parse a .gitmodules file correctly' do
parser = described_class.new(<<-'GITMODULES'.strip_heredoc) data = <<~GITMODULES
[submodule "vendor/libgit2"] [submodule "vendor/libgit2"]
path = vendor/libgit2 path = vendor/libgit2
[submodule "vendor/libgit2"] [submodule "vendor/libgit2"]
...@@ -16,6 +16,7 @@ describe Gitlab::Git::GitmodulesParser do ...@@ -16,6 +16,7 @@ describe Gitlab::Git::GitmodulesParser do
url = https://example.com/another/project url = https://example.com/another/project
GITMODULES GITMODULES
parser = described_class.new(data.gsub("\n", "\r\n"))
modules = parser.parse modules = parser.parse
expect(modules).to eq({ expect(modules).to eq({
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment