Commit a7c42451 authored by Douwe Maan's avatar Douwe Maan
Browse files

Merge branch 'rs-relative-links-to-root' into 'master'

Support a single directory traversal in RelativeLinkFilter

Prior, if we were viewing a blob at
`` and
it contained a relative link such as `[README](../`, the
resulting link when viewing the blob would be:
`` which omits the
`master` ref, resulting in a 404.


See merge request !2247
parents 2459d516 d9d2e8a3
......@@ -91,7 +91,7 @@ def build_relative_path(path, request_path)
parts = request_path.split('/')
parts.pop if path_type(request_path) != 'tree'
while parts.length > 1 && path.start_with?('../')
while path.start_with?('../')
path.sub!('../', '')
......@@ -92,6 +92,14 @@ def link(path)
to eq "/#{project_path}/blob/#{ref}/doc/api/"
it 'rebuilds relative URL for a file in the repository root' do
relative_link = link('../')
doc = filter(relative_link, requested_path: 'doc/')
to eq "/#{project_path}/blob/#{ref}/"
it 'rebuilds relative URL for a file in the repo with an anchor' do
doc = filter(link(''))
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