diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-03-15 13:28:14 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-03-15 13:28:14 +0000 |
commit | e5e1b7c33d11a6268e937f79cdb9ee54984ebc2d (patch) | |
tree | 6593a984c796c3ba37bd7e5f834f2da39bff6f0a | |
parent | 2a2b65c4b97a039c553d829d56a58875cde91754 (diff) | |
parent | f97dffdd6eaf7e2bd4804309417cabe8b50efa90 (diff) | |
download | gitlab-ce-e5e1b7c33d11a6268e937f79cdb9ee54984ebc2d.tar.gz |
Merge branch 'fix-42459-#-in-branch' into 'master'
Manually escape '#' when building relative uris, closes #42459
Closes #42459
See merge request gitlab-org/gitlab-ce!17679
-rw-r--r-- | changelogs/unreleased/fix-42459---in-branch.yml | 5 | ||||
-rw-r--r-- | lib/banzai/filter/relative_link_filter.rb | 2 | ||||
-rw-r--r-- | spec/lib/banzai/filter/relative_link_filter_spec.rb | 17 |
3 files changed, 23 insertions, 1 deletions
diff --git a/changelogs/unreleased/fix-42459---in-branch.yml b/changelogs/unreleased/fix-42459---in-branch.yml new file mode 100644 index 00000000000..26cc2046206 --- /dev/null +++ b/changelogs/unreleased/fix-42459---in-branch.yml @@ -0,0 +1,5 @@ +--- +title: Fix relative uri when "#" is in branch name +merge_request: +author: Jan +type: fixed diff --git a/lib/banzai/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb index 9bdedeb6615..262458a872a 100644 --- a/lib/banzai/filter/relative_link_filter.rb +++ b/lib/banzai/filter/relative_link_filter.rb @@ -84,7 +84,7 @@ module Banzai relative_url_root, project.full_path, uri_type(file_path), - Addressable::URI.escape(ref), + Addressable::URI.escape(ref).gsub('#', '%23'), Addressable::URI.escape(file_path) ].compact.join('/').squeeze('/').chomp('/') diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb index 3ca4652f7cc..ba8dc68ceda 100644 --- a/spec/lib/banzai/filter/relative_link_filter_spec.rb +++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb @@ -217,6 +217,23 @@ describe Banzai::Filter::RelativeLinkFilter do end end + context 'when ref name contains special chars' do + let(:ref) {'mark#\'@],+;-._/#@!$&()+down'} + + it 'correctly escapes the ref' do + # Adressable won't escape the '#', so we do this manually + ref_escaped = 'mark%23\'@%5D,+;-._/%23@!$&()+down' + + # Stub this method so the branch doesn't actually need to be in the repo + allow_any_instance_of(described_class).to receive(:uri_type).and_return(:raw) + + doc = filter(link('files/images/logo-black.png')) + + expect(doc.at_css('a')['href']) + .to eq "/#{project_path}/raw/#{ref_escaped}/files/images/logo-black.png" + end + end + context 'when requested path is a directory with space in the repo' do let(:ref) { 'master' } let(:commit) { project.commit('38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e') } |