Commit 7b427998 authored by Rémy Coutable's avatar Rémy Coutable

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
parents 8775c368 b791dcc0
...@@ -8,6 +8,7 @@ v 8.11.0 (unreleased) ...@@ -8,6 +8,7 @@ v 8.11.0 (unreleased)
- Convert switch icon into icon font (ClemMakesApps) - Convert switch icon into icon font (ClemMakesApps)
- Remove magic comments (`# encoding: UTF-8`) from Ruby files. !5456 (winniehell) - Remove magic comments (`# encoding: UTF-8`) from Ruby files. !5456 (winniehell)
- Add support for relative links starting with ./ or / to RelativeLinkFilter (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) - Fix CI status icon link underline (ClemMakesApps)
- The Repository class is now instrumented - The Repository class is now instrumented
- Cache the commit author in RequestStore to avoid extra lookups in PostReceive - Cache the commit author in RequestStore to avoid extra lookups in PostReceive
......
...@@ -35,6 +35,7 @@ module Banzai ...@@ -35,6 +35,7 @@ module Banzai
def process_link_attr(html_attr) def process_link_attr(html_attr)
return if html_attr.blank? return if html_attr.blank?
return if html_attr.value.start_with?('//')
uri = URI(html_attr.value) uri = URI(html_attr.value)
if uri.relative? && uri.path.present? if uri.relative? && uri.path.present?
...@@ -92,7 +93,7 @@ module Banzai ...@@ -92,7 +93,7 @@ module Banzai
parts = request_path.split('/') parts = request_path.split('/')
parts.pop if uri_type(request_path) != :tree parts.pop if uri_type(request_path) != :tree
path.sub!(%r{^\./}, '') path.sub!(%r{\A\./}, '')
while path.start_with?('../') while path.start_with?('../')
parts.pop parts.pop
......
...@@ -84,6 +84,11 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do ...@@ -84,6 +84,11 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
to eq "/#{project_path}/blob/#{ref}/doc/api/README.md" to eq "/#{project_path}/blob/#{ref}/doc/api/README.md"
end 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 it 'rebuilds relative URL for a file in the repo' do
doc = filter(link('doc/api/README.md')) doc = filter(link('doc/api/README.md'))
expect(doc.at_css('a')['href']). expect(doc.at_css('a')['href']).
......
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