summaryrefslogtreecommitdiff
path: root/app/validators
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@gitlab.com>2017-04-11 15:51:33 +0200
committerBob Van Landuyt <bob@gitlab.com>2017-05-01 11:14:24 +0200
commitf7511caa5f26c071c61908a48440a95c5f45eb69 (patch)
treed5f9f5206f54c072d04e19d24ff732912f0e80fa /app/validators
parente4f5b7ca2184473985ef216df676ddb737fb26af (diff)
downloadgitlab-ce-f7511caa5f26c071c61908a48440a95c5f45eb69.tar.gz
Split off validating full paths
The first part of a full path needs to be validated as a `top_level` while the rest need to be validated as `wildcard`
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/namespace_validator.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/app/validators/namespace_validator.rb b/app/validators/namespace_validator.rb
index 4d99b09e98f..8a0e18612ec 100644
--- a/app/validators/namespace_validator.rb
+++ b/app/validators/namespace_validator.rb
@@ -77,12 +77,14 @@ class NamespaceValidator < ActiveModel::EachValidator
STRICT_RESERVED = (TOP_LEVEL_ROUTES | WILDCARD_ROUTES)
def self.valid_full_path?(full_path)
- pieces = full_path.split('/')
- first_part = pieces.first
- pieces.all? do |namespace|
- type = first_part == namespace ? :top_level : :wildcard
- valid?(namespace, type: type)
- end
+ path_segments = full_path.split('/')
+ root_segment = path_segments.shift
+
+ valid?(root_segment, type: :top_level) && valid_wildcard_segments?(path_segments)
+ end
+
+ def self.valid_wildcard_segments?(segments)
+ segments.all? { |segment| valid?(segment, type: :wildcard) }
end
def self.valid?(value, type: :strict)