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

151 lines
4.2 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module Gitlab
module Regex
extend self
def project_name_regex
2020-03-09 13:42:32 +05:30
# The character range \p{Alnum} overlaps with \u{00A9}-\u{1f9ff}
# hence the Ruby warning.
# https://gitlab.com/gitlab-org/gitlab/merge_requests/23165#not-easy-fixable
@project_name_regex ||= /\A[\p{Alnum}\u{00A9}-\u{1f9ff}_][\p{Alnum}\p{Pd}\u{00A9}-\u{1f9ff}_\. ]*\z/.freeze
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
def project_name_regex_message
2017-08-17 22:00:37 +05:30
"can contain only letters, digits, emojis, '_', '.', dash, space. " \
"It must start with letter, digit, emoji or '_'."
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
##
2017-09-10 17:25:29 +05:30
# Docker Distribution Registry repository / tag name rules
#
# See https://github.com/docker/distribution/blob/master/reference/regexp.go.
2017-08-17 22:00:37 +05:30
#
def container_repository_name_regex
2020-01-01 13:55:28 +05:30
@container_repository_regex ||= %r{\A[a-z0-9]+((?:[._/]|__|[-]{0,10})[a-z0-9]+)*\Z}
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
##
# We do not use regexp anchors here because these are not allowed when
# used as a routing constraint.
#
def container_registry_tag_regex
@container_registry_tag_regex ||= /[\w][\w.-]{0,127}/
end
def environment_name_regex_chars
2018-03-17 18:26:18 +05:30
'a-zA-Z0-9_/\\$\\{\\}\\. \\-'
2017-09-10 17:25:29 +05:30
end
2018-03-27 19:54:05 +05:30
def environment_name_regex_chars_without_slash
'a-zA-Z0-9_\\$\\{\\}\\. -'
end
def environment_name_regex
2018-03-27 19:54:05 +05:30
@environment_name_regex ||= /\A[#{environment_name_regex_chars_without_slash}]([#{environment_name_regex_chars}]*[#{environment_name_regex_chars_without_slash}])?\z/.freeze
end
def environment_name_regex_message
2018-03-27 19:54:05 +05:30
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', and spaces, but it cannot start or end with '/'"
end
2017-08-17 22:00:37 +05:30
2019-10-12 21:52:04 +05:30
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
2017-08-17 22:00:37 +05:30
def kubernetes_namespace_regex
/\A[a-z0-9]([-a-z0-9]*[a-z0-9])?\z/
end
def kubernetes_namespace_regex_message
2018-03-17 18:26:18 +05:30
"can contain only lowercase letters, digits, and '-'. " \
"Must start with a letter, and cannot end with '-'"
2017-08-17 22:00:37 +05:30
end
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
2018-03-17 18:26:18 +05:30
def build_trace_section_regex
@build_trace_section_regexp ||= /section_((?:start)|(?:end)):(\d+):([a-zA-Z0-9_.-]+)\r\033\[0K/.freeze
end
2018-11-18 11:00:15 +05:30
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
2019-10-12 21:52:04 +05:30
# 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-11-18 11:00:15 +05:30
def jira_transition_id_regex
@jira_transition_id_regex ||= /\d+/
end
2019-12-04 20:38:33 +05:30
def breakline_regex
@breakline_regex ||= /\r\n|\r|\n/
end
2019-12-21 20:55:43 +05:30
2019-12-26 22:10:19 +05:30
# 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-12-21 20:55:43 +05:30
# 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-12-26 22:10:19 +05:30
'must be a valid Amazon Resource Name'
end
def utc_date_regex
@utc_date_regex ||= /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/.freeze
2019-12-21 20:55:43 +05:30
end
2014-09-02 18:07:02 +05:30
end
end
2019-12-04 20:38:33 +05:30
Gitlab::Regex.prepend_if_ee('EE::Gitlab::Regex')