summaryrefslogtreecommitdiff
path: root/lib/gitlab/regex.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-03-24 14:55:14 +0100
committerDouwe Maan <douwe@gitlab.com>2015-03-27 11:09:29 +0100
commitdfe0f9eedf040c6c266161239b6e2ede77c2b7dc (patch)
treeff2c2ea02422b4d67ff98a6f256e1b68f52a3883 /lib/gitlab/regex.rb
parent3f7531d6f2974ea75ab8e67bc93049f674ddb672 (diff)
downloadgitlab-ce-dfe0f9eedf040c6c266161239b6e2ede77c2b7dc.tar.gz
Use more specific regexes.
Diffstat (limited to 'lib/gitlab/regex.rb')
-rw-r--r--lib/gitlab/regex.rb64
1 files changed, 34 insertions, 30 deletions
diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb
index cf6e260f257..08fcf9c6dc0 100644
--- a/lib/gitlab/regex.rb
+++ b/lib/gitlab/regex.rb
@@ -2,49 +2,64 @@ module Gitlab
module Regex
extend self
- def username_regex
- default_regex
+ def namespace_regex
+ @namespace_regex ||= /\A[a-zA-Z0-9_.][a-zA-Z0-9_\-\.]*(?<!\.git)\z/.freeze
end
- def username_regex_message
- default_regex_message
+ def namespace_regex_message
+ "can contain only letters, digits, '_', '-' and '.'. " \
+ "Cannot start with '-' or end in '.git'" \
+ end
+
+
+ def namespace_name_regex
+ @namespace_name_regex ||= /\A[a-zA-Z0-9_\-\. ]*\z/.freeze
end
+ def namespace_name_regex_message
+ "can contain only letters, digits, '_', '-', '.' and space."
+ end
+
+
def project_name_regex
- /\A[a-zA-Z0-9_.][a-zA-Z0-9_\-\. ]*\z/
+ @project_name_regex ||= /\A[a-zA-Z0-9_.][a-zA-Z0-9_\-\. ]*\z/.freeze
end
- def project_regex_message
- "can contain only letters, digits, '_', '-' and '.' and space. " \
+ def project_name_regex_message
+ "can contain only letters, digits, '_', '-', '.' and space. " \
"It must start with letter, digit or '_'."
end
- def name_regex
- /\A[a-zA-Z0-9_\-\. ]*\z/
+
+ def project_path_regex
+ @project_path_regex ||= /\A[a-zA-Z0-9_.][a-zA-Z0-9_\-\.]*(?<!\.git)\z/.freeze
end
- def name_regex_message
- "can contain only letters, digits, '_', '-' and '.' and space."
+ def project_path_regex_message
+ "can contain only letters, digits, '_', '-' and '.'. " \
+ "Cannot start with '-' or end in '.git'" \
end
- def path_regex
- default_regex
+
+ def file_name_regex
+ @file_name_regex ||= /\A[a-zA-Z0-9_\-\.]*\z/.freeze
end
- def path_regex_message
- default_regex_message
+ def file_name_regex_message
+ "can contain only letters, digits, '_', '-' and '.'. "
end
+
def archive_formats_regex
- #|zip|tar| tar.gz | tar.bz2 |
- /(zip|tar|tar\.gz|tgz|gz|tar\.bz2|tbz|tbz2|tb2|bz2)/
+ # |zip|tar| tar.gz | tar.bz2 |
+ @archive_formats_regex ||= /(zip|tar|tar\.gz|tgz|gz|tar\.bz2|tbz|tbz2|tb2|bz2)/.freeze
end
def git_reference_regex
# Valid git ref regex, see:
# https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
- %r{
+ @git_reference_regex ||= %r{
(?!
(?# doesn't begins with)
\/| (?# rule #6)
@@ -60,18 +75,7 @@ module Gitlab
(?# doesn't end with)
(?<!\.lock) (?# rule #1)
(?<![\/.]) (?# rule #6-7)
- }x
- end
-
- protected
-
- def default_regex_message
- "can contain only letters, digits, '_', '-' and '.'. " \
- "Cannot start with '-' or end in '.git'" \
- end
-
- def default_regex
- /\A[a-zA-Z0-9_.][a-zA-Z0-9_\-\.]*(?<!\.git)\z/
+ }x.freeze
end
end
end