Merge branch 'rs-relative-links-to-root' into 'master'
Support a single directory traversal in RelativeLinkFilter Prior, if we were viewing a blob at `https://example.com/namespace/project/blob/master/doc/some-file.md` and it contained a relative link such as `[README](../README.md)`, the resulting link when viewing the blob would be: `https://example.com/namespace/project/blob/README.md` which omits the `master` ref, resulting in a 404. Fixes https://gitlab.com/gitlab-org/release-tools/issues/3 See merge request !2247
This commit is contained in:
commit
a7c424515c
2 changed files with 9 additions and 1 deletions
|
@ -91,7 +91,7 @@ module Banzai
|
|||
parts = request_path.split('/')
|
||||
parts.pop if path_type(request_path) != 'tree'
|
||||
|
||||
while parts.length > 1 && path.start_with?('../')
|
||||
while path.start_with?('../')
|
||||
parts.pop
|
||||
path.sub!('../', '')
|
||||
end
|
||||
|
|
|
@ -92,6 +92,14 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do
|
|||
to eq "/#{project_path}/blob/#{ref}/doc/api/README.md"
|
||||
end
|
||||
|
||||
it 'rebuilds relative URL for a file in the repository root' do
|
||||
relative_link = link('../README.md')
|
||||
doc = filter(relative_link, requested_path: 'doc/some-file.md')
|
||||
|
||||
expect(doc.at_css('a')['href']).
|
||||
to eq "/#{project_path}/blob/#{ref}/README.md"
|
||||
end
|
||||
|
||||
it 'rebuilds relative URL for a file in the repo with an anchor' do
|
||||
doc = filter(link('README.md#section'))
|
||||
expect(doc.at_css('a')['href']).
|
||||
|
|
Loading…
Reference in a new issue