gitlab-org--gitlab-foss/lib/gitlab/regex.rb

51 lines
1 KiB
Ruby
Raw Normal View History

2012-11-27 22:14:05 -05:00
module Gitlab
module Regex
extend self
def username_regex
default_regex
end
2012-12-25 17:50:41 -05:00
def project_name_regex
/\A[a-zA-Z0-9][a-zA-Z0-9_\-\. ]*\z/
2012-12-25 17:50:41 -05:00
end
def name_regex
/\A[a-zA-Z0-9_\-\. ]*\z/
end
2012-11-27 22:14:05 -05:00
def path_regex
default_regex
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{
(?!
# 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)
}x
end
2012-11-27 22:14:05 -05:00
protected
def default_regex
/\A[a-zA-Z0-9][a-zA-Z0-9_\-\.]*\z/
2012-11-27 22:14:05 -05:00
end
end
end