diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-08-11 15:29:36 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-08-11 15:29:36 +0300 |
commit | 7f3228ec74725c02efb0e23ff8380eaa03739891 (patch) | |
tree | 409192c60bfa07405ed558b1e12acfd153d899ef | |
parent | b8d48ca84f275b1d39f8745c8e1c842e995a63a0 (diff) | |
parent | 01af2c98b64149cf8ba906b4bcf7650b7abdd446 (diff) |
Merge branch 'master' of github.com:gitlabhq/gitlabhq
-rw-r--r-- | CHANGELOG | 5 | ||||
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | lib/api/files.rb | 2 | ||||
-rw-r--r-- | lib/rouge/formatters/html_gitlab.rb | 41 | ||||
-rw-r--r-- | spec/helpers/blob_helper_spec.rb | 16 | ||||
-rw-r--r-- | spec/helpers/events_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/files_spec.rb | 31 |
8 files changed, 78 insertions, 25 deletions
diff --git a/CHANGELOG b/CHANGELOG index d228ef616d4..74b41106b97 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 7.14.0 (unreleased) + - Fix corrupted binary files when using API files endpoint (Stan Hu) - Show incompatible projects in Bitbucket import status (Stan Hu) - Fix coloring of diffs on MR Discussion-tab (Gert Goet) - Fix "Network" and "Graphs" pages for branches with encoded slashes (Stan Hu) @@ -47,6 +48,10 @@ v 7.14.0 (unreleased) - Improve MR merge widget text and UI consistency. - Improve text in MR "How To Merge" modal. - Cache all events + - Order commits by date when comparing branches + - Fix bug causing error when the target branch of a symbolic ref was deleted + - Include branch/tag name in archive file and directory name + - Add dropzone upload progress v 7.13.3 - Fix bug causing Bitbucket importer to crash when OAuth application had been removed. @@ -38,7 +38,7 @@ gem "browser", '~> 0.8.0' # Extracting information from a git repository # Provide access to Gitlab::Git library -gem "gitlab_git", '~> 7.2.6' +gem "gitlab_git", '~> 7.2.11' # Ruby/Rack Git Smart-HTTP Server Handler # GitLab fork with a lot of changes (improved thread-safety, better memory usage etc) diff --git a/Gemfile.lock b/Gemfile.lock index 643c513161f..5ba6948cbc1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -271,7 +271,7 @@ GEM mime-types (~> 1.19) gitlab_emoji (0.1.0) gemojione (~> 2.0) - gitlab_git (7.2.6) + gitlab_git (7.2.11) activesupport (~> 4.0) charlock_holmes (~> 0.6) gitlab-linguist (~> 3.0) @@ -783,7 +783,7 @@ DEPENDENCIES gitlab-grack (~> 2.0.2) gitlab-linguist (~> 3.0.1) gitlab_emoji (~> 0.1) - gitlab_git (~> 7.2.6) + gitlab_git (~> 7.2.11) gitlab_meta (= 7.0) gitlab_omniauth-ldap (= 1.2.1) gollum-lib (~> 4.0.2) diff --git a/lib/api/files.rb b/lib/api/files.rb index c7b30cf2f07..308c84dd135 100644 --- a/lib/api/files.rb +++ b/lib/api/files.rb @@ -67,7 +67,7 @@ module API file_path: blob.path, size: blob.size, encoding: "base64", - content: Base64.encode64(blob.data), + content: Base64.strict_encode64(blob.data), ref: ref, blob_id: blob.id, commit_id: commit.id, diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb index 3f92212243d..6762ca47c32 100644 --- a/lib/rouge/formatters/html_gitlab.rb +++ b/lib/rouge/formatters/html_gitlab.rb @@ -93,16 +93,27 @@ module Rouge end def process_tokens(tokens) - num_lines = 0 - last_val = '' - rendered = '' + rendered = [] + current_line = '' tokens.each do |tok, val| - last_val = val - num_lines += val.scan(/\n/).size - rendered << span(tok, val) + # In the case of multi-line values (e.g. comments), we need to apply + # styling to each line since span elements are inline. + val.lines.each do |line| + stripped = line.chomp + current_line << span(tok, stripped) + + if line.end_with?("\n") + rendered << current_line + current_line = '' + end + end end + # Add leftover text + rendered << current_line if current_line.present? + + num_lines = rendered.size numbers = (@linenostart..num_lines + @linenostart - 1).to_a { numbers: numbers, code: rendered } @@ -117,9 +128,8 @@ module Rouge numbers.join("\n") end - def wrap_lines(rendered) + def wrap_lines(lines) if @lineanchors - lines = rendered.split("\n") lines = lines.each_with_index.map do |line, index| number = index + @linenostart @@ -136,24 +146,17 @@ module Rouge lines.join("\n") else if @linenos == 'inline' - lines = rendered.split("\n") lines = lines.each_with_index.map do |line, index| number = index + @linenostart "<span class=\"linenos\">#{number}</span>#{line}" end lines.join("\n") else - rendered + lines.join("\n") end end end - def wrap_values(val, element) - lines = val.split("\n") - lines = lines.map{ |x| "<span #{element}>#{x}</span>" } - lines.join("\n") - end - def span(tok, val) # http://stackoverflow.com/a/1600584/2587286 val = CGI.escapeHTML(val) @@ -161,13 +164,11 @@ module Rouge if tok.shortname.empty? val else - # In the case of multi-line values (e.g. comments), we need to apply - # styling to each line since span elements are inline. if @inline_theme rules = @inline_theme.style_for(tok).rendered_rules - wrap_values(val, "style=\"#{rules.to_a.join(';')}\"") + "<span style=\"#{rules.to_a.join(';')}\"#{val}</span>" else - wrap_values(val, "class=\"#{tok.shortname}\"") + "<span class=\"#{tok.shortname}\">#{val}</span>" end end end diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index 76009c36099..b8bba36439a 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -47,5 +47,21 @@ describe BlobHelper do expect(lines[1].text).to eq(' This is line 2.') expect(lines[2].text).to eq(' """') end + + context 'diff highlighting' do + let(:blob_name) { 'test.diff' } + let(:blob_content) { "+aaa\n+bbb\n- ccc\n ddd\n"} + let(:expected) do + %q(<span id="LC1" class="line"><span class="gi">+aaa</span></span> +<span id="LC2" class="line"><span class="gi">+bbb</span></span> +<span id="LC3" class="line"><span class="gd">- ccc</span></span> +<span id="LC4" class="line"> ddd</span>) + end + + it 'should highlight each line properly' do + result = highlight(blob_name, blob_content, nowrap: true, continue: false) + expect(result).to eq(expected) + end + end end end diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb index b392371deb4..da58ab98462 100644 --- a/spec/helpers/events_helper_spec.rb +++ b/spec/helpers/events_helper_spec.rb @@ -58,7 +58,7 @@ describe EventsHelper do expected = '<pre class="code highlight white ruby">' \ "<code><span class=\"k\">def</span> <span class=\"nf\">test</span>\n" \ " <span class=\"s1\">\'hello world\'</span>\n" \ - "<span class=\"k\">end</span>\n" \ + "<span class=\"k\">end</span>" \ '</code></pre>' expect(event_note(input)).to eq(expected) end diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index 8cb8790c339..042e6352567 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -117,4 +117,35 @@ describe API::API, api: true do expect(response.status).to eq(400) end end + + describe "POST /projects/:id/repository/files with binary file" do + let(:file_path) { 'test.bin' } + let(:put_params) do + { + file_path: file_path, + branch_name: 'master', + content: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=', + commit_message: 'Binary file with a \n should not be touched', + encoding: 'base64' + } + end + let(:get_params) do + { + file_path: file_path, + ref: 'master', + } + end + + before do + post api("/projects/#{project.id}/repository/files", user), put_params + end + + it "remains unchanged" do + get api("/projects/#{project.id}/repository/files", user), get_params + expect(response.status).to eq(200) + expect(json_response['file_path']).to eq(file_path) + expect(json_response['file_name']).to eq(file_path) + expect(json_response['content']).to eq(put_params[:content]) + end + end end |