2012-11-27 22:14:05 -05:00
|
|
|
module Gitlab
|
|
|
|
module Regex
|
|
|
|
extend self
|
|
|
|
|
|
|
|
def username_regex
|
|
|
|
default_regex
|
|
|
|
end
|
|
|
|
|
2014-06-26 03:53:01 -04:00
|
|
|
def username_regex_message
|
|
|
|
default_regex_message
|
|
|
|
end
|
|
|
|
|
2012-12-25 17:50:41 -05:00
|
|
|
def project_name_regex
|
2014-03-06 08:08:40 -05:00
|
|
|
/\A[a-zA-Z0-9_][a-zA-Z0-9_\-\. ]*\z/
|
2012-12-25 17:50:41 -05:00
|
|
|
end
|
|
|
|
|
2014-06-26 03:53:01 -04:00
|
|
|
def project_regex_message
|
|
|
|
"can contain only letters, digits, '_', '-' and '.' and space. " \
|
|
|
|
"It must start with letter, digit or '_'."
|
|
|
|
end
|
|
|
|
|
2013-02-18 02:28:18 -05:00
|
|
|
def name_regex
|
|
|
|
/\A[a-zA-Z0-9_\-\. ]*\z/
|
|
|
|
end
|
|
|
|
|
2014-06-26 03:53:01 -04:00
|
|
|
def name_regex_message
|
|
|
|
"can contain only letters, digits, '_', '-' and '.' and space."
|
|
|
|
end
|
|
|
|
|
2012-11-27 22:14:05 -05:00
|
|
|
def path_regex
|
|
|
|
default_regex
|
|
|
|
end
|
2014-01-14 12:26:01 -05:00
|
|
|
|
2014-06-26 03:53:01 -04:00
|
|
|
def path_regex_message
|
|
|
|
default_regex_message
|
|
|
|
end
|
|
|
|
|
2013-12-20 14:12:44 -05:00
|
|
|
def archive_formats_regex
|
|
|
|
#|zip|tar| tar.gz | tar.bz2 |
|
|
|
|
/(zip|tar|tar\.gz|tgz|gz|tar\.bz2|tbz|tbz2|tb2|bz2)/
|
|
|
|
end
|
2012-11-27 22:14:05 -05:00
|
|
|
|
2013-09-02 06:48:32 -04:00
|
|
|
def git_reference_regex
|
|
|
|
# Valid git ref regex, see:
|
|
|
|
# https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
|
|
|
|
|
|
|
|
%r{
|
|
|
|
(?!
|
2013-12-23 21:01:38 -05:00
|
|
|
(?# doesn't begins with)
|
|
|
|
\/| (?# rule #6)
|
|
|
|
(?# doesn't contain)
|
2013-09-02 06:48:32 -04:00
|
|
|
.*(?:
|
2013-12-23 21:01:38 -05:00
|
|
|
[\/.]\.| (?# rule #1,3)
|
|
|
|
\/\/| (?# rule #6)
|
|
|
|
@\{| (?# rule #8)
|
|
|
|
\\ (?# rule #9)
|
2013-09-02 06:48:32 -04:00
|
|
|
)
|
|
|
|
)
|
2013-12-23 21:01:38 -05:00
|
|
|
[^\000-\040\177~^:?*\[]+ (?# rule #4-5)
|
|
|
|
(?# doesn't end with)
|
|
|
|
(?<!\.lock) (?# rule #1)
|
|
|
|
(?<![\/.]) (?# rule #6-7)
|
2013-09-02 06:48:32 -04:00
|
|
|
}x
|
|
|
|
end
|
|
|
|
|
2012-11-27 22:14:05 -05:00
|
|
|
protected
|
|
|
|
|
2014-06-26 03:53:01 -04:00
|
|
|
def default_regex_message
|
|
|
|
"can contain only letters, digits, '_', '-' and '.'. " \
|
|
|
|
"It must start with letter, digit or '_', optionally preceeded by '.'. " \
|
|
|
|
"It must not end in '.git'."
|
|
|
|
end
|
|
|
|
|
2012-11-27 22:14:05 -05:00
|
|
|
def default_regex
|
2014-07-08 11:15:23 -04:00
|
|
|
/\A[a-zA-Z0-9_.][a-zA-Z0-9_\-\.]*(?<!\.git)\z/
|
2012-11-27 22:14:05 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|