summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-08-05 09:34:40 +0000
committerRémy Coutable <remy@rymai.me>2016-08-05 09:34:40 +0000
commit7b4279984ca9b517f6089931e0fa8c152e195b61 (patch)
treed48b67b427f9dbc86632fe8ceeb2c08c389e00d4
parent8775c36830b889ce2b7433cd35c92ff86cc5554e (diff)
parentb791dcc05b379a64c1370bc4be8d0aac60b9c31b (diff)
downloadgitlab-ce-7b4279984ca9b517f6089931e0fa8c152e195b61.tar.gz
Merge branch 'leading-slashes-relative-links' into 'master'
Ignore URLs starting with // in Markdown links ## What does this MR do? Render `[foo](//bar/baz)` as `<a href="//bar/baz">foo</a>`. ## Why was this MR needed? `[foo](//bar/baz)` currently renders as `<a href="//bar/gitlab-org/gitlab-ce/master/baz">foo</a>` ## What are the relevant issue numbers? fixes #7032 See merge request !5677
-rw-r--r--CHANGELOG1
-rw-r--r--lib/banzai/filter/relative_link_filter.rb3
-rw-r--r--spec/lib/banzai/filter/relative_link_filter_spec.rb5
3 files changed, 8 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 32f9ec2ce23..7465230fafe 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -8,6 +8,7 @@ v 8.11.0 (unreleased)
- Convert switch icon into icon font (ClemMakesApps)
- Remove magic comments (`# encoding: UTF-8`) from Ruby files. !5456 (winniehell)
- Add support for relative links starting with ./ or / to RelativeLinkFilter (winniehell)
+ - Ignore URLs starting with // in Markdown links !5677 (winniehell)
- Fix CI status icon link underline (ClemMakesApps)
- The Repository class is now instrumented
- Cache the commit author in RequestStore to avoid extra lookups in PostReceive
diff --git a/lib/banzai/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb
index 5b73fc8fcee..46762d401fb 100644
--- a/lib/banzai/filter/relative_link_filter.rb
+++ b/lib/banzai/filter/relative_link_filter.rb
@@ -35,6 +35,7 @@ module Banzai
def process_link_attr(html_attr)
return if html_attr.blank?
+ return if html_attr.value.start_with?('//')
uri = URI(html_attr.value)
if uri.relative? && uri.path.present?
@@ -92,7 +93,7 @@ module Banzai
parts = request_path.split('/')
parts.pop if uri_type(request_path) != :tree
- path.sub!(%r{^\./}, '')
+ path.sub!(%r{\A\./}, '')
while path.start_with?('../')
parts.pop
diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb
index 224baca8030..bda8d2ce38a 100644
--- a/spec/lib/banzai/filter/relative_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb
@@ -84,6 +84,11 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
to eq "/#{project_path}/blob/#{ref}/doc/api/README.md"
end
+ it 'ignores absolute URLs with two leading slashes' do
+ doc = filter(link('//doc/api/README.md'))
+ expect(doc.at_css('a')['href']).to eq '//doc/api/README.md'
+ end
+
it 'rebuilds relative URL for a file in the repo' do
doc = filter(link('doc/api/README.md'))
expect(doc.at_css('a')['href']).