debian-mirror-gitlab/lib/gitlab/regex.rb

107 lines
3.1 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module Gitlab
module Regex
extend self
2016-11-03 12:29:30 +05:30
NAMESPACE_REGEX_STR = '(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])(?<!\.git|\.atom)'.freeze
2015-04-26 12:48:37 +05:30
def namespace_regex
@namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
def namespace_regex_message
"can contain only letters, digits, '_', '-' and '.'. " \
2016-11-03 12:29:30 +05:30
"Cannot start with '-' or end in '.', '.git' or '.atom'." \
2015-04-26 12:48:37 +05:30
end
def namespace_name_regex
2015-09-11 14:41:01 +05:30
@namespace_name_regex ||= /\A[\p{Alnum}\p{Pd}_\. ]*\z/.freeze
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
def namespace_name_regex_message
2015-09-11 14:41:01 +05:30
"can contain only letters, digits, '_', '.', dash and space."
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
def project_name_regex
2015-09-11 14:41:01 +05:30
@project_name_regex ||= /\A[\p{Alnum}_][\p{Alnum}\p{Pd}_\. ]*\z/.freeze
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
def project_name_regex_message
2015-09-11 14:41:01 +05:30
"can contain only letters, digits, '_', '.', dash and space. " \
2014-09-02 18:07:02 +05:30
"It must start with letter, digit or '_'."
end
2015-04-26 12:48:37 +05:30
def project_path_regex
2016-04-02 18:10:28 +05:30
@project_path_regex ||= /\A[a-zA-Z0-9_.][a-zA-Z0-9_\-\.]*(?<!\.git|\.atom)\z/.freeze
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
def project_path_regex_message
"can contain only letters, digits, '_', '-' and '.'. " \
2016-04-02 18:10:28 +05:30
"Cannot start with '-', end in '.git' or end in '.atom'" \
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
def file_name_regex
2016-04-02 18:10:28 +05:30
@file_name_regex ||= /\A[a-zA-Z0-9_\-\.\@]*\z/.freeze
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
def file_name_regex_message
2016-11-03 12:29:30 +05:30
"can contain only letters, digits, '_', '-', '@' and '.'."
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
def file_path_regex
2016-04-02 18:10:28 +05:30
@file_path_regex ||= /\A[a-zA-Z0-9_\-\.\/\@]*\z/.freeze
2015-11-26 14:37:03 +05:30
end
def file_path_regex_message
2016-11-03 12:29:30 +05:30
"can contain only letters, digits, '_', '-', '@' and '.'. Separate directories with a '/'."
2015-11-26 14:37:03 +05:30
end
def directory_traversal_regex
@directory_traversal_regex ||= /\.{2}/.freeze
end
def directory_traversal_regex_message
2016-11-03 12:29:30 +05:30
"cannot include directory traversal."
2015-11-26 14:37:03 +05:30
end
2014-09-02 18:07:02 +05:30
def archive_formats_regex
2015-04-26 12:48:37 +05:30
# |zip|tar| tar.gz | tar.bz2 |
@archive_formats_regex ||= /(zip|tar|tar\.gz|tgz|gz|tar\.bz2|tbz|tbz2|tb2|bz2)/.freeze
2014-09-02 18:07:02 +05:30
end
def git_reference_regex
# Valid git ref regex, see:
# https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
2015-04-26 12:48:37 +05:30
@git_reference_regex ||= %r{
2014-09-02 18:07:02 +05:30
(?!
(?# doesn't begins with)
\/| (?# rule #6)
(?# doesn't contain)
.*(?:
[\/.]\.| (?# rule #1,3)
\/\/| (?# rule #6)
@\{| (?# rule #8)
\\ (?# rule #9)
)
)
[^\000-\040\177~^:?*\[]+ (?# rule #4-5)
(?# doesn't end with)
(?<!\.lock) (?# rule #1)
(?<![\/.]) (?# rule #6-7)
2015-04-26 12:48:37 +05:30
}x.freeze
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
def container_registry_reference_regex
git_reference_regex
end
def environment_name_regex
2016-09-29 09:46:39 +05:30
@environment_name_regex ||= /\A[a-zA-Z0-9_\\\/\${}. -]+\z/.freeze
end
def environment_name_regex_message
2016-09-29 09:46:39 +05:30
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.' and spaces"
end
2014-09-02 18:07:02 +05:30
end
end