diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index d899ed3ba25f4ecd45ed118d8cff029cbcc4ce1d..49d3eaa576feaa650c9da7c18d3b9821e17eb37a 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -432,7 +432,7 @@ def init_from_gitaly(commit) @committer_name = commit.committer.name.dup @committer_email = commit.committer.email.dup @parent_ids = Array(commit.parent_ids) - @trailers = commit.trailers.to_h { |t| [t.key, t.value] } + @trailers = commit.trailers.to_h { |t| [t.key, encode!(t.value)] } @extended_trailers = parse_commit_trailers(commit.trailers) @referenced_by = Array(commit.referenced_by) end @@ -440,7 +440,7 @@ def init_from_gitaly(commit) # Turn the commit trailers into a hash of key: [value, value] arrays def parse_commit_trailers(trailers) trailers.each_with_object({}) do |trailer, hash| - (hash[trailer.key] ||= []) << trailer.value + (hash[trailer.key] ||= []) << encode!(trailer.value) end end diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb index a924137b8ec74abfd3d6a1fa722d16388b4939a6..767ca360b9675085638d6c4a23c38c26c6c11998 100644 --- a/spec/lib/gitlab/git/commit_spec.rb +++ b/spec/lib/gitlab/git/commit_spec.rb @@ -51,6 +51,30 @@ ) end + context 'non-ASCII content' do + let(:body) do + body = +<<~BODY + Äpfel + + Changelog: Äpfel + BODY + + [subject, "\n", body.force_encoding("ASCII-8BIT")].join + end + + it "parses non-ASCII commit trailers" do + expect(commit.trailers).to eq( + { 'Changelog' => 'Äpfel' } + ) + end + + it "parses non-ASCII extended commit trailers" do + expect(commit.extended_trailers).to eq( + { 'Changelog' => ['Äpfel'] } + ) + end + end + context 'non-UTC dates' do let(:seconds) { Time.now.to_i }