2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-11-27 22:14:05 -05:00
|
|
|
module Gitlab
|
|
|
|
module Regex
|
|
|
|
extend self
|
|
|
|
|
2012-12-25 17:50:41 -05:00
|
|
|
def project_name_regex
|
2016-11-11 06:27:23 -05:00
|
|
|
@project_name_regex ||= /\A[\p{Alnum}\u{00A9}-\u{1f9c0}_][\p{Alnum}\p{Pd}\u{00A9}-\u{1f9c0}_\. ]*\z/.freeze
|
2012-12-25 17:50:41 -05:00
|
|
|
end
|
|
|
|
|
2015-03-24 09:55:14 -04:00
|
|
|
def project_name_regex_message
|
2016-11-11 06:27:23 -05:00
|
|
|
"can contain only letters, digits, emojis, '_', '.', dash, space. " \
|
|
|
|
"It must start with letter, digit, emoji or '_'."
|
2014-06-26 03:53:01 -04:00
|
|
|
end
|
|
|
|
|
2017-04-03 05:38:39 -04:00
|
|
|
##
|
2017-07-19 04:30:57 -04:00
|
|
|
# Docker Distribution Registry repository / tag name rules
|
|
|
|
#
|
|
|
|
# See https://github.com/docker/distribution/blob/master/reference/regexp.go.
|
2017-04-03 05:38:39 -04:00
|
|
|
#
|
|
|
|
def container_repository_name_regex
|
2017-11-16 03:31:07 -05:00
|
|
|
@container_repository_regex ||= %r{\A[a-z0-9]+((?:[._/]|__|[-])[a-z0-9]+)*\Z}
|
2017-04-03 05:38:39 -04:00
|
|
|
end
|
|
|
|
|
2017-07-19 04:52:03 -04:00
|
|
|
##
|
|
|
|
# We do not use regexp anchors here because these are not allowed when
|
|
|
|
# used as a routing constraint.
|
|
|
|
#
|
2017-07-19 04:30:57 -04:00
|
|
|
def container_registry_tag_regex
|
|
|
|
@container_registry_tag_regex ||= /[\w][\w.-]{0,127}/
|
|
|
|
end
|
|
|
|
|
2017-07-06 03:45:38 -04:00
|
|
|
def environment_name_regex_chars
|
2017-12-14 03:56:00 -05:00
|
|
|
'a-zA-Z0-9_/\\$\\{\\}\\. \\-'
|
2017-07-06 03:45:38 -04:00
|
|
|
end
|
|
|
|
|
2017-11-18 22:01:01 -05:00
|
|
|
def environment_name_regex_chars_without_slash
|
|
|
|
'a-zA-Z0-9_\\$\\{\\}\\. -'
|
|
|
|
end
|
|
|
|
|
2016-06-14 07:04:21 -04:00
|
|
|
def environment_name_regex
|
2017-11-18 22:01:01 -05:00
|
|
|
@environment_name_regex ||= /\A[#{environment_name_regex_chars_without_slash}]([#{environment_name_regex_chars}]*[#{environment_name_regex_chars_without_slash}])?\z/.freeze
|
2016-06-14 07:04:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def environment_name_regex_message
|
2017-11-18 22:01:01 -05:00
|
|
|
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', and spaces, but it cannot start or end with '/'"
|
2016-06-14 07:04:21 -04:00
|
|
|
end
|
2016-12-08 11:36:26 -05:00
|
|
|
|
2019-08-08 14:51:52 -04:00
|
|
|
def environment_scope_regex_chars
|
|
|
|
"#{environment_name_regex_chars}\\*"
|
|
|
|
end
|
|
|
|
|
|
|
|
def environment_scope_regex
|
|
|
|
@environment_scope_regex ||= /\A[#{environment_scope_regex_chars}]+\z/.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def environment_scope_regex_message
|
|
|
|
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', '*' and spaces"
|
|
|
|
end
|
|
|
|
|
2016-12-08 11:36:26 -05:00
|
|
|
def kubernetes_namespace_regex
|
|
|
|
/\A[a-z0-9]([-a-z0-9]*[a-z0-9])?\z/
|
|
|
|
end
|
|
|
|
|
|
|
|
def kubernetes_namespace_regex_message
|
2017-08-22 02:12:27 -04:00
|
|
|
"can contain only lowercase letters, digits, and '-'. " \
|
|
|
|
"Must start with a letter, and cannot end with '-'"
|
2016-12-08 11:36:26 -05:00
|
|
|
end
|
2016-12-07 20:09:18 -05:00
|
|
|
|
|
|
|
def environment_slug_regex
|
|
|
|
@environment_slug_regex ||= /\A[a-z]([a-z0-9-]*[a-z0-9])?\z/.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def environment_slug_regex_message
|
|
|
|
"can contain only lowercase letters, digits, and '-'. " \
|
|
|
|
"Must start with a letter, and cannot end with '-'"
|
|
|
|
end
|
2017-09-25 12:54:08 -04:00
|
|
|
|
|
|
|
def build_trace_section_regex
|
2017-12-21 13:34:34 -05:00
|
|
|
@build_trace_section_regexp ||= /section_((?:start)|(?:end)):(\d+):([a-zA-Z0-9_.-]+)\r\033\[0K/.freeze
|
2017-09-25 12:54:08 -04:00
|
|
|
end
|
2018-07-06 06:35:30 -04:00
|
|
|
|
|
|
|
def markdown_code_or_html_blocks
|
|
|
|
@markdown_code_or_html_blocks ||= %r{
|
|
|
|
(?<code>
|
|
|
|
# Code blocks:
|
|
|
|
# ```
|
|
|
|
# Anything, including `>>>` blocks which are ignored by this filter
|
|
|
|
# ```
|
|
|
|
|
|
|
|
^```
|
|
|
|
.+?
|
|
|
|
\n```\ *$
|
|
|
|
)
|
|
|
|
|
|
|
|
|
(?<html>
|
|
|
|
# HTML block:
|
|
|
|
# <tag>
|
|
|
|
# Anything, including `>>>` blocks which are ignored by this filter
|
|
|
|
# </tag>
|
|
|
|
|
|
|
|
^<[^>]+?>\ *\n
|
|
|
|
.+?
|
|
|
|
\n<\/[^>]+?>\ *$
|
|
|
|
)
|
|
|
|
}mx
|
|
|
|
end
|
2018-07-31 15:17:22 -04:00
|
|
|
|
2019-07-25 05:29:51 -04:00
|
|
|
# Based on Jira's project key format
|
|
|
|
# https://confluence.atlassian.com/adminjiraserver073/changing-the-project-key-format-861253229.html
|
|
|
|
def jira_issue_key_regex
|
|
|
|
@jira_issue_key_regex ||= /[A-Z][A-Z_0-9]+-\d+/
|
|
|
|
end
|
|
|
|
|
2018-07-31 15:17:22 -04:00
|
|
|
def jira_transition_id_regex
|
|
|
|
@jira_transition_id_regex ||= /\d+/
|
|
|
|
end
|
2019-09-02 06:43:54 -04:00
|
|
|
|
|
|
|
def breakline_regex
|
|
|
|
@breakline_regex ||= /\r\n|\r|\n/
|
|
|
|
end
|
2019-10-16 17:07:22 -04:00
|
|
|
|
2019-11-08 01:06:24 -05:00
|
|
|
# https://docs.aws.amazon.com/general/latest/gr/acct-identifiers.html
|
|
|
|
def aws_account_id_regex
|
|
|
|
/\A\d{12}\z/
|
|
|
|
end
|
|
|
|
|
|
|
|
def aws_account_id_message
|
|
|
|
'must be a 12-digit number'
|
|
|
|
end
|
|
|
|
|
2019-10-16 17:07:22 -04:00
|
|
|
# https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
|
|
|
|
def aws_arn_regex
|
|
|
|
/\Aarn:\S+\z/
|
|
|
|
end
|
|
|
|
|
|
|
|
def aws_arn_regex_message
|
2019-11-08 01:06:24 -05:00
|
|
|
'must be a valid Amazon Resource Name'
|
2019-10-16 17:07:22 -04:00
|
|
|
end
|
2019-10-31 14:06:53 -04:00
|
|
|
|
|
|
|
def utc_date_regex
|
|
|
|
@utc_date_regex ||= /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/.freeze
|
|
|
|
end
|
2012-11-27 22:14:05 -05:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Gitlab::Regex.prepend_if_ee('EE::Gitlab::Regex')
|