summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Mazetto <gabriel@gitlab.com>2016-12-12 17:15:40 +0000
committerGabriel Mazetto <gabriel@gitlab.com>2016-12-12 17:15:40 +0000
commit3445136b9b0b8367b151170509fabe613389a50d (patch)
treeb4ca45d8a08c02280cb6f29812633f34f8842528
parentdf629173d97ffcb7ecda306e83024abc7abae3f7 (diff)
parent17e3d3fde8c9a83f58d797c5f62f36b59eedd870 (diff)
downloadgitlab-ce-3445136b9b0b8367b151170509fabe613389a50d.tar.gz
Merge branch 'unescape-relative-path' into 'master'
Avoid escaping relative links in Markdown twice ## What does this MR do? Avoid escaping relative links in Markdown twice. ## Why was this MR needed? Relative links with special characters (e.g. spaces) were escaped twice. ## What are the relevant issue numbers? closes #25191, #25318 See merge request !7940
-rw-r--r--changelogs/unreleased/unescape-relative-path.yml4
-rw-r--r--lib/banzai/filter/relative_link_filter.rb14
-rw-r--r--spec/lib/banzai/filter/relative_link_filter_spec.rb2
3 files changed, 11 insertions, 9 deletions
diff --git a/changelogs/unreleased/unescape-relative-path.yml b/changelogs/unreleased/unescape-relative-path.yml
new file mode 100644
index 00000000000..755b0379a16
--- /dev/null
+++ b/changelogs/unreleased/unescape-relative-path.yml
@@ -0,0 +1,4 @@
+---
+title: Avoid escaping relative links in Markdown twice
+merge_request: 7940
+author: winniehell
diff --git a/lib/banzai/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb
index f09d78be0ce..9e23c8f8c55 100644
--- a/lib/banzai/filter/relative_link_filter.rb
+++ b/lib/banzai/filter/relative_link_filter.rb
@@ -46,7 +46,7 @@ module Banzai
end
def rebuild_relative_uri(uri)
- file_path = relative_file_path(uri.path)
+ file_path = relative_file_path(uri)
uri.path = [
relative_url_root,
@@ -59,8 +59,10 @@ module Banzai
uri
end
- def relative_file_path(path)
- nested_path = build_relative_path(path, context[:requested_path])
+ def relative_file_path(uri)
+ path = Addressable::URI.unescape(uri.path)
+ request_path = Addressable::URI.unescape(context[:requested_path])
+ nested_path = build_relative_path(path, request_path)
file_exists?(nested_path) ? nested_path : path
end
@@ -108,11 +110,7 @@ module Banzai
end
def uri_type(path)
- @uri_types[path] ||= begin
- unescaped_path = Addressable::URI.unescape(path)
-
- current_commit.uri_type(unescaped_path)
- end
+ @uri_types[path] ||= current_commit.uri_type(path)
end
def current_commit
diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb
index 2bfa51deb20..df2dd173b57 100644
--- a/spec/lib/banzai/filter/relative_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb
@@ -175,7 +175,7 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
allow_any_instance_of(described_class).to receive(:uri_type).and_return(:raw)
doc = filter(image(escaped))
- expect(doc.at_css('img')['src']).to match '/raw/'
+ expect(doc.at_css('img')['src']).to eq "/#{project_path}/raw/#{Addressable::URI.escape(ref)}/#{escaped}"
end
context 'when requested path is a file in the repo' do