Commit 70611316 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor namespace regex

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 76ff9fff
...@@ -3,7 +3,7 @@ require 'constraints/group_url_constrainer' ...@@ -3,7 +3,7 @@ require 'constraints/group_url_constrainer'
constraints(GroupUrlConstrainer.new) do constraints(GroupUrlConstrainer.new) do
scope(path: ':id', scope(path: ':id',
as: :group, as: :group,
constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }, constraints: { id: Gitlab::Regex.namespace_route_regex },
controller: :groups) do controller: :groups) do
get '/', action: :show get '/', action: :show
patch '/', action: :update patch '/', action: :update
......
...@@ -14,31 +14,32 @@ end ...@@ -14,31 +14,32 @@ end
constraints(UserUrlConstrainer.new) do constraints(UserUrlConstrainer.new) do
scope(path: ':username', scope(path: ':username',
as: :user, as: :user,
constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }, constraints: { username: Gitlab::Regex.namespace_route_regex },
controller: :users) do controller: :users) do
get '/', action: :show get '/', action: :show
end end
end end
scope(path: 'users/:username', scope(constraints: { username: Gitlab::Regex.namespace_route_regex }) do
as: :user, scope(path: 'users/:username',
constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }, as: :user,
controller: :users) do controller: :users) do
get :calendar get :calendar
get :calendar_activities get :calendar_activities
get :groups get :groups
get :projects get :projects
get :contributed, as: :contributed_projects get :contributed, as: :contributed_projects
get :snippets get :snippets
get :exists get :exists
get '/', to: redirect('/%{username}') get '/', to: redirect('/%{username}')
end end
# Compatibility with old routing # Compatibility with old routing
# TODO (dzaporozhets): remove in 10.0 # TODO (dzaporozhets): remove in 10.0
get '/u/:username', to: redirect('/%{username}'), constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ } get '/u/:username', to: redirect('/%{username}')
# TODO (dzaporozhets): remove in 9.0 # TODO (dzaporozhets): remove in 9.0
get '/u/:username/groups', to: redirect('/users/%{username}/groups'), constraints: { username: /[a-zA-Z.0-9_\-]+/ } get '/u/:username/groups', to: redirect('/users/%{username}/groups')
get '/u/:username/projects', to: redirect('/users/%{username}/projects'), constraints: { username: /[a-zA-Z.0-9_\-]+/ } get '/u/:username/projects', to: redirect('/users/%{username}/projects')
get '/u/:username/snippets', to: redirect('/users/%{username}/snippets'), constraints: { username: /[a-zA-Z.0-9_\-]+/ } get '/u/:username/snippets', to: redirect('/users/%{username}/snippets')
get '/u/:username/contributed', to: redirect('/users/%{username}/contributed'), constraints: { username: /[a-zA-Z.0-9_\-]+/ } get '/u/:username/contributed', to: redirect('/users/%{username}/contributed')
end
...@@ -8,6 +8,10 @@ module Gitlab ...@@ -8,6 +8,10 @@ module Gitlab
@namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze @namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze
end end
def namespace_route_regex
@namespace_route_regex ||= /#{NAMESPACE_REGEX_STR}/.freeze
end
def namespace_regex_message def namespace_regex_message
"can contain only letters, digits, '_', '-' and '.'. " \ "can contain only letters, digits, '_', '-' and '.'. " \
"Cannot start with '-' or end in '.', '.git' or '.atom'." \ "Cannot start with '-' or end in '.', '.git' or '.atom'." \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment