diff --git a/CHANGELOG b/CHANGELOG index 95aeda301f79490b787ba0cc2cc86cce504a3373..0061bba03b94751a0d2764113c4512a7a6848d2c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -44,6 +44,7 @@ v 8.10.3 (unreleased) - Properly abort a merge when merge conflicts occur - Ignore invalid IPs in X-Forwarded-For when trusted proxies are configured. - Fix Import/Export issue importing milestones and labels not associated properly + - Trim extra displayed carriage returns in diffs and files with CRLFs v 8.10.2 - User can now search branches by name. !5144 diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb index f818dc78d34c7f3f326ed41de2cda3d5f8a6cb3b..4edfd0150740b2d28483f9767d1014d339ae841d 100644 --- a/lib/rouge/formatters/html_gitlab.rb +++ b/lib/rouge/formatters/html_gitlab.rb @@ -18,7 +18,7 @@ module Rouge is_first = false yield %() - line.each { |token, value| yield span(token, value) } + line.each { |token, value| yield span(token, value.chomp) } yield %() @line_number += 1 diff --git a/spec/lib/gitlab/highlight_spec.rb b/spec/lib/gitlab/highlight_spec.rb index 364532e94e30956eb37967dee45f6b85cdacc545..80a9473d6aa3fc1dbdf39f9756a2f8ccbc76f6b3 100644 --- a/spec/lib/gitlab/highlight_spec.rb +++ b/spec/lib/gitlab/highlight_spec.rb @@ -17,6 +17,18 @@ describe Gitlab::Highlight, lib: true do expect(lines[21]).to eq(%Q{ unless File.directory?(path)\n}) expect(lines[26]).to eq(%Q{ @cmd_status = 0\n}) end + + describe 'with CRLF' do + let(:branch) { 'crlf-diff' } + let(:blob) { repository.blob_at_branch(branch, path) } + let(:lines) do + Gitlab::Highlight.highlight_lines(project.repository, 'crlf-diff-test', 'files/whitespace') + end + + it 'strips extra LFs' do + expect(lines[0]).to eq("test ") + end + end end describe 'custom highlighting from .gitattributes' do diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 3735abe230219f255dc5fd45fc7778ad03f1c86e..4561aa9644d45f99822281e0abe69e56abdf9768 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -21,7 +21,8 @@ module TestEnv 'expand-collapse-diffs' => '4842455', 'expand-collapse-files' => '025db92', 'expand-collapse-lines' => '238e82d', - 'video' => '8879059' + 'video' => '8879059', + 'crlf-diff' => '5938907' } # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily