BigW Consortium Gitlab

Commit a51a3fb8 by Robert Speicher

Merge branch 'rs-mr-1050-followup' into 'master'

Add spec to RelativeLinkFilter for Unicode filenames Adds specs for changes added in !1050 See merge request !1078
parents 327013ac 7ca7770e
...@@ -3,7 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -3,7 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 7.14.0 (unreleased) v 7.14.0 (unreleased)
- Fix network graph when branch name has single quotes (Stan Hu) - Fix network graph when branch name has single quotes (Stan Hu)
- Upgrade gitlab_git to version 7.2.6 to fix Error 500 when creating network graphs (Stan Hu) - Upgrade gitlab_git to version 7.2.6 to fix Error 500 when creating network graphs (Stan Hu)
- Fix the image file that contains non-ascii character is not displayed(Hiroyuki Sato) - Add support for Unicode filenames in relative links (Hiroyuki Sato)
- Fix URL used for refreshing notes if relative_url is present (Bartłomiej Święcki) - Fix URL used for refreshing notes if relative_url is present (Bartłomiej Święcki)
- Fix commit data retrieval when branch name has single quotes (Stan Hu) - Fix commit data retrieval when branch name has single quotes (Stan Hu)
- Check that project was actually created rather than just validated in import:repos task (Stan Hu) - Check that project was actually created rather than just validated in import:repos task (Stan Hu)
......
...@@ -99,15 +99,24 @@ module Gitlab ...@@ -99,15 +99,24 @@ module Gitlab
# Returns a String # Returns a String
def path_type(path) def path_type(path)
unescaped_path = Addressable::URI.unescape(path) unescaped_path = Addressable::URI.unescape(path)
if repository.tree(current_sha, unescaped_path).entries.any?
if tree?(unescaped_path)
'tree' 'tree'
elsif repository.blob_at(current_sha, unescaped_path).try(:image?) elsif image?(unescaped_path)
'raw' 'raw'
else else
'blob' 'blob'
end end
end end
def tree?(path)
repository.tree(current_sha, path).entries.any?
end
def image?(path)
repository.blob_at(current_sha, path).try(:image?)
end
def current_sha def current_sha
context[:commit].try(:id) || context[:commit].try(:id) ||
ref ? repository.commit(ref).try(:sha) : repository.head_commit.sha ref ? repository.commit(ref).try(:sha) : repository.head_commit.sha
......
# encoding: UTF-8
require 'spec_helper' require 'spec_helper'
module Gitlab::Markdown module Gitlab::Markdown
...@@ -101,6 +103,20 @@ module Gitlab::Markdown ...@@ -101,6 +103,20 @@ module Gitlab::Markdown
expect(doc.at_css('a')['href']).to eq 'http://example.com' expect(doc.at_css('a')['href']).to eq 'http://example.com'
end end
it 'supports Unicode filenames' do
path = 'files/images/한글.png'
escaped = Addressable::URI.escape(path)
# Stub these methods so the file doesn't actually need to be in the repo
allow_any_instance_of(described_class).to receive(:file_exists?).
and_return(true)
allow_any_instance_of(described_class).
to receive(:image?).with(path).and_return(true)
doc = filter(image(escaped))
expect(doc.at_css('img')['src']).to match '/raw/'
end
context 'when requested path is a file in the repo' do context 'when requested path is a file in the repo' do
let(:requested_path) { 'doc/api/README.md' } let(:requested_path) { 'doc/api/README.md' }
include_examples :relative_to_requested include_examples :relative_to_requested
......
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