Skip to content

Commit d9027df

Browse files
committed
Merge pull request gitlabhq#2706 from jfut/gh-issue-2602
Remove relative_url_root from path. Fixes #2602
2 parents aa99660 + 79b9249 commit d9027df

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/extracts_path.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def extract_ref(input)
5050

5151
return pair unless @project
5252

53+
# Remove relative_url_root from path
54+
input.gsub!(/^#{Gitlab.config.gitlab.relative_url_root}/, "")
5355
# Remove project, actions and all other staff from path
5456
input.gsub!(/^\/#{Regexp.escape(@project.path_with_namespace)}/, "")
5557
input.gsub!(/^\/(tree|commits|blame|blob|refs)\//, "") # remove actions

spec/lib/extracts_path_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,28 @@
7373
extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435').should == ['v2.0.0', 'CHANGELOG']
7474
end
7575
end
76+
77+
context "with a fullpath and a relative_url_root" do
78+
before do
79+
Gitlab.config.gitlab.stub(relative_url_root: '/relative')
80+
end
81+
82+
it "extracts a valid branch with relative_url_root" do
83+
extract_ref('/relative/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG']
84+
end
85+
86+
it "extracts a valid tag" do
87+
extract_ref('/relative/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG']
88+
end
89+
90+
it "extracts a valid commit SHA" do
91+
extract_ref('/relative/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should ==
92+
['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG']
93+
end
94+
95+
it "extracts a timestamp" do
96+
extract_ref('/relative/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435').should == ['v2.0.0', 'CHANGELOG']
97+
end
98+
end
7699
end
77100
end

0 commit comments

Comments
 (0)