Allow RelativeLinkFilter to go up multiple directories
This commit is contained in:
parent
619f04c196
commit
2b94f5fb06
|
@ -91,8 +91,7 @@ module Gitlab
|
|||
parts = request_path.split('/')
|
||||
parts.pop if path_type(request_path) != 'tree'
|
||||
|
||||
# Allow for going up one directory
|
||||
if parts.length > 1 && path.start_with?('../')
|
||||
while parts.length > 1 && path.start_with?('../')
|
||||
parts.pop
|
||||
path.sub!('../', '')
|
||||
end
|
||||
|
|
|
@ -85,6 +85,14 @@ module Gitlab::Markdown
|
|||
to eq "/#{project_path}/blob/#{ref}/doc/api/README.md"
|
||||
end
|
||||
|
||||
it 'rebuilds relative URL for a file in the repo up multiple directories' do
|
||||
relative_link = link('../../../api/README.md')
|
||||
doc = filter(relative_link, requested_path: 'doc/foo/bar/baz/README.md')
|
||||
|
||||
expect(doc.at_css('a')['href']).
|
||||
to eq "/#{project_path}/blob/#{ref}/doc/api/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 New Issue