From 79b9249ff44c5ccbef44a8d9420a3fff369d932a Mon Sep 17 00:00:00 2001 From: Jun Futagawa Date: Wed, 23 Jan 2013 17:29:46 +0900 Subject: [PATCH] Remove relative_url_root from path. Fixes #2602 Files and Commits render a 404 when running with relative_url_root. --- lib/extracts_path.rb | 2 ++ spec/lib/extracts_path_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index 270a0aaa..12700e4f 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -50,6 +50,8 @@ module ExtractsPath return pair unless @project + # Remove relative_url_root from path + input.gsub!(/^#{Gitlab.config.gitlab.relative_url_root}/, "") # Remove project, actions and all other staff from path input.gsub!(/^\/#{Regexp.escape(@project.path_with_namespace)}/, "") input.gsub!(/^\/(tree|commits|blame|blob|refs)\//, "") # remove actions diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb index deb6499e..ee20ae79 100644 --- a/spec/lib/extracts_path_spec.rb +++ b/spec/lib/extracts_path_spec.rb @@ -73,5 +73,28 @@ describe ExtractsPath do extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435').should == ['v2.0.0', 'CHANGELOG'] end end + + context "with a fullpath and a relative_url_root" do + before do + Gitlab.config.gitlab.stub(relative_url_root: '/relative') + end + + it "extracts a valid branch with relative_url_root" do + extract_ref('/relative/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG'] + end + + it "extracts a valid tag" do + extract_ref('/relative/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG'] + end + + it "extracts a valid commit SHA" do + extract_ref('/relative/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should == + ['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG'] + end + + it "extracts a timestamp" do + extract_ref('/relative/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435').should == ['v2.0.0', 'CHANGELOG'] + end + end end end