summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-03-30 15:15:31 -0700
committerStan Hu <stanhu@gmail.com>2018-03-30 15:23:44 -0700
commit6fd1d07cfc5244e518e3ee94bf6b796cfe38c3b0 (patch)
tree5a30f71029aac0a7236453f5c20cd6a32cd99684
parentd2ad0bcc0254524c71c7422935f53c267b5b6923 (diff)
downloadgitlab-ce-sh-cleanup-crlf-gitmodules.tar.gz
Handle CR-LFs properly in .gitmodules filesh-cleanup-crlf-gitmodules
Any submodule lines that had a CR-LF ending would be ignored by the parser. Closes gitlab-org/gitlab-ce#2262
-rw-r--r--lib/gitlab/git/gitmodules_parser.rb4
-rw-r--r--spec/lib/gitlab/git/gitmodules_parser_spec.rb3
2 files changed, 5 insertions, 2 deletions
diff --git a/lib/gitlab/git/gitmodules_parser.rb b/lib/gitlab/git/gitmodules_parser.rb
index 4a43b9b444d..4b505312f60 100644
--- a/lib/gitlab/git/gitmodules_parser.rb
+++ b/lib/gitlab/git/gitmodules_parser.rb
@@ -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
diff --git a/spec/lib/gitlab/git/gitmodules_parser_spec.rb b/spec/lib/gitlab/git/gitmodules_parser_spec.rb
index 143aa2218c9..6fd2b33486b 100644
--- a/spec/lib/gitlab/git/gitmodules_parser_spec.rb
+++ b/spec/lib/gitlab/git/gitmodules_parser_spec.rb
@@ -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({