diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2016-10-24 12:42:43 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-10-25 15:25:41 +0200 |
commit | 6d84f057d451026904fe257f9571178e674ade5a (patch) | |
tree | 36f118ec9a384c96aa7145d7d55d6827a8f2610a | |
parent | 8742a18ea2329c0468f0998b5b869fbd5545e4fb (diff) | |
download | gitlab-ce-6d84f057d451026904fe257f9571178e674ade5a.tar.gz |
Merge branch 'dz-fix-constrainer-for-relative-url' into 'master'
Fix constrainers for relative url
Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/23675
See merge request !7071
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/constraints/namespace_url_constrainer.rb | 13 | ||||
-rw-r--r-- | spec/lib/constraints/namespace_url_constrainer_spec.rb | 10 |
3 files changed, 23 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b2210fcea43..2eb914ef181 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Please view this file on the master branch, on stable branches it's out of date. - Expire and build repository cache after project import. !7064 - Fix bug where labels would be assigned to issues that were moved. !7065 - Fix reply-by-email not working due to queue name mismatch. !7068 + - Fix 404 for group pages when GitLab setup uses relative url. !7071 ## 8.13.0 (2016-10-22) diff --git a/lib/constraints/namespace_url_constrainer.rb b/lib/constraints/namespace_url_constrainer.rb index 23920193743..91b70143f11 100644 --- a/lib/constraints/namespace_url_constrainer.rb +++ b/lib/constraints/namespace_url_constrainer.rb @@ -1,6 +1,9 @@ class NamespaceUrlConstrainer def matches?(request) - id = request.path.sub(/\A\/+/, '').split('/').first.sub(/.atom\z/, '') + id = request.path + id = id.sub(/\A#{relative_url_root}/, '') if relative_url_root + id = id.sub(/\A\/+/, '').split('/').first + id = id.sub(/.atom\z/, '') if id if id =~ Gitlab::Regex.namespace_regex find_resource(id) @@ -10,4 +13,12 @@ class NamespaceUrlConstrainer def find_resource(id) Namespace.find_by_path(id) end + + private + + def relative_url_root + if defined?(Gitlab::Application.config.relative_url_root) + Gitlab::Application.config.relative_url_root + end + end end diff --git a/spec/lib/constraints/namespace_url_constrainer_spec.rb b/spec/lib/constraints/namespace_url_constrainer_spec.rb index a5feaacb8ee..7814711fe27 100644 --- a/spec/lib/constraints/namespace_url_constrainer_spec.rb +++ b/spec/lib/constraints/namespace_url_constrainer_spec.rb @@ -17,6 +17,16 @@ describe NamespaceUrlConstrainer, lib: true do it { expect(subject.matches?(request '/g/gitlab')).to be_falsey } it { expect(subject.matches?(request '/.gitlab')).to be_falsey } end + + context 'relative url' do + before do + allow(Gitlab::Application.config).to receive(:relative_url_root) { '/gitlab' } + end + + it { expect(subject.matches?(request '/gitlab/gitlab')).to be_truthy } + it { expect(subject.matches?(request '/gitlab/gitlab-ce')).to be_falsey } + it { expect(subject.matches?(request '/gitlab/')).to be_falsey } + end end def request(path) |