diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-09-20 19:21:33 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-09-20 19:21:33 -0400 |
commit | 2b94f5fb06ef061fb49a7dadcbb95c0954bc9860 (patch) | |
tree | d44b697c910b7bdecdbfee932aec015db1f7feb2 | |
parent | 619f04c196731b2a274802dfb4b4d3c3664e5465 (diff) | |
download | gitlab-ce-2b94f5fb06ef061fb49a7dadcbb95c0954bc9860.tar.gz |
Allow RelativeLinkFilter to go up multiple directoriesrs-relative-link-up-one
-rw-r--r-- | lib/gitlab/markdown/relative_link_filter.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/markdown/relative_link_filter_spec.rb | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/gitlab/markdown/relative_link_filter.rb b/lib/gitlab/markdown/relative_link_filter.rb index d613c205509..6ee3d1ce039 100644 --- a/lib/gitlab/markdown/relative_link_filter.rb +++ b/lib/gitlab/markdown/relative_link_filter.rb @@ -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 diff --git a/spec/lib/gitlab/markdown/relative_link_filter_spec.rb b/spec/lib/gitlab/markdown/relative_link_filter_spec.rb index ab9c2008ea7..027336ceb73 100644 --- a/spec/lib/gitlab/markdown/relative_link_filter_spec.rb +++ b/spec/lib/gitlab/markdown/relative_link_filter_spec.rb @@ -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']). |