Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2015-07-31 04:47:41 +0300
committerRobert Speicher <robert@gitlab.com>2015-07-31 04:47:41 +0300
commita51a3fb8ed92a58b375125b19f75c3d4c545571a (patch)
treed4483d8e96c64d4ae3f21224697e8f44d4696431
parent327013ace9933eaec75c7e41f5918a311e861d12 (diff)
parent7ca7770e984d802f9f35579d6b5c08ad63a3052a (diff)
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
-rw-r--r--CHANGELOG2
-rw-r--r--lib/gitlab/markdown/relative_link_filter.rb13
-rw-r--r--spec/lib/gitlab/markdown/relative_link_filter_spec.rb16
3 files changed, 28 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 2f43492b54e..bfff6a56777 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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)
- 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)
- - 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 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)
diff --git a/lib/gitlab/markdown/relative_link_filter.rb b/lib/gitlab/markdown/relative_link_filter.rb
index 3eaceba5323..30f50b82996 100644
--- a/lib/gitlab/markdown/relative_link_filter.rb
+++ b/lib/gitlab/markdown/relative_link_filter.rb
@@ -99,15 +99,24 @@ module Gitlab
# Returns a String
def path_type(path)
unescaped_path = Addressable::URI.unescape(path)
- if repository.tree(current_sha, unescaped_path).entries.any?
+
+ if tree?(unescaped_path)
'tree'
- elsif repository.blob_at(current_sha, unescaped_path).try(:image?)
+ elsif image?(unescaped_path)
'raw'
else
'blob'
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
context[:commit].try(:id) ||
ref ? repository.commit(ref).try(:sha) : repository.head_commit.sha
diff --git a/spec/lib/gitlab/markdown/relative_link_filter_spec.rb b/spec/lib/gitlab/markdown/relative_link_filter_spec.rb
index 5ee5310825d..7f4d67e403f 100644
--- a/spec/lib/gitlab/markdown/relative_link_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/relative_link_filter_spec.rb
@@ -1,3 +1,5 @@
+# encoding: UTF-8
+
require 'spec_helper'
module Gitlab::Markdown
@@ -101,6 +103,20 @@ module Gitlab::Markdown
expect(doc.at_css('a')['href']).to eq 'http://example.com'
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
let(:requested_path) { 'doc/api/README.md' }
include_examples :relative_to_requested