2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-11-27 22:14:05 -05:00
|
|
|
module Gitlab
|
|
|
|
module Regex
|
2020-06-09 08:08:55 -04:00
|
|
|
module Packages
|
2020-08-18 08:10:16 -04:00
|
|
|
CONAN_RECIPE_FILES = %w[conanfile.py conanmanifest.txt conan_sources.tgz conan_export.tgz].freeze
|
2020-06-09 08:08:55 -04:00
|
|
|
CONAN_PACKAGE_FILES = %w[conaninfo.txt conanmanifest.txt conan_package.tgz].freeze
|
|
|
|
|
2021-04-21 11:09:35 -04:00
|
|
|
API_PATH_REGEX = %r{^/api/v\d+/(projects/[^/]+/|groups?/[^/]+/-/)?packages/[A-Za-z]+}.freeze
|
|
|
|
|
2020-06-09 08:08:55 -04:00
|
|
|
def conan_package_reference_regex
|
|
|
|
@conan_package_reference_regex ||= %r{\A[A-Za-z0-9]+\z}.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def conan_revision_regex
|
|
|
|
@conan_revision_regex ||= %r{\A0\z}.freeze
|
|
|
|
end
|
|
|
|
|
2021-12-02 10:10:48 -05:00
|
|
|
def conan_recipe_user_channel_regex
|
|
|
|
%r{\A(_|#{conan_name_regex})\z}.freeze
|
|
|
|
end
|
|
|
|
|
2020-06-09 08:08:55 -04:00
|
|
|
def conan_recipe_component_regex
|
2021-12-02 10:10:48 -05:00
|
|
|
# https://docs.conan.io/en/latest/reference/conanfile/attributes.html#name
|
|
|
|
@conan_recipe_component_regex ||= %r{\A#{conan_name_regex}\z}.freeze
|
2020-06-09 08:08:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def composer_package_version_regex
|
2021-09-17 11:11:44 -04:00
|
|
|
# see https://github.com/composer/semver/blob/31f3ea725711245195f62e54ffa402d8ef2fdba9/src/VersionParser.php#L215
|
|
|
|
@composer_package_version_regex ||= %r{\Av?((\d++)(\.(?:\d++|[xX*]))?(\.(?:\d++|[xX*]))?(\.(?:\d++|[xX*]))?)?\z}.freeze
|
2020-06-09 08:08:55 -04:00
|
|
|
end
|
|
|
|
|
2020-10-30 02:08:54 -04:00
|
|
|
def composer_dev_version_regex
|
|
|
|
@composer_dev_version_regex ||= %r{(^dev-)|(-dev$)}.freeze
|
|
|
|
end
|
|
|
|
|
2020-06-09 08:08:55 -04:00
|
|
|
def package_name_regex
|
2021-01-07 13:10:38 -05:00
|
|
|
@package_name_regex ||=
|
|
|
|
%r{
|
|
|
|
\A\@?
|
|
|
|
(?> # atomic group to prevent backtracking
|
|
|
|
(([\w\-\.\+]*)\/)*([\w\-\.]+)
|
|
|
|
)
|
|
|
|
@?
|
|
|
|
(?> # atomic group to prevent backtracking
|
|
|
|
(([\w\-\.\+]*)\/)*([\w\-\.]*)
|
|
|
|
)
|
|
|
|
\z
|
|
|
|
}x.freeze
|
2020-06-09 08:08:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def maven_file_name_regex
|
|
|
|
@maven_file_name_regex ||= %r{\A[A-Za-z0-9\.\_\-\+]+\z}.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def maven_path_regex
|
|
|
|
@maven_path_regex ||= %r{\A\@?(([\w\-\.]*)/)*([\w\-\.\+]*)\z}.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def maven_app_name_regex
|
|
|
|
@maven_app_name_regex ||= /\A[\w\-\.]+\z/.freeze
|
|
|
|
end
|
|
|
|
|
2020-06-18 17:09:05 -04:00
|
|
|
def maven_version_regex
|
2021-12-06 22:12:22 -05:00
|
|
|
@maven_version_regex ||= /\A(?!.*\.\.)[\w+.-]+\z/.freeze
|
2020-06-18 17:09:05 -04:00
|
|
|
end
|
|
|
|
|
2020-06-09 08:08:55 -04:00
|
|
|
def maven_app_group_regex
|
|
|
|
maven_app_name_regex
|
|
|
|
end
|
|
|
|
|
2021-02-17 13:09:19 -05:00
|
|
|
def npm_package_name_regex
|
|
|
|
@npm_package_name_regex ||= %r{\A(?:@(#{Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX})/)?[-+\.\_a-zA-Z0-9]+\z}
|
|
|
|
end
|
|
|
|
|
2020-11-02 16:09:10 -05:00
|
|
|
def nuget_package_name_regex
|
|
|
|
@nuget_package_name_regex ||= %r{\A[-+\.\_a-zA-Z0-9]+\z}.freeze
|
|
|
|
end
|
|
|
|
|
2020-10-06 17:09:22 -04:00
|
|
|
def nuget_version_regex
|
|
|
|
@nuget_version_regex ||= /
|
2022-01-06 10:16:10 -05:00
|
|
|
\A#{_semver_major_regex}
|
|
|
|
\.#{_semver_minor_regex}
|
|
|
|
(\.#{_semver_patch_regex})?
|
|
|
|
(\.\d*)?
|
|
|
|
#{_semver_prerelease_build_regex}\z
|
2020-10-06 17:09:22 -04:00
|
|
|
/x.freeze
|
|
|
|
end
|
|
|
|
|
2021-05-13 20:11:05 -04:00
|
|
|
def terraform_module_package_name_regex
|
|
|
|
@terraform_module_package_name_regex ||= %r{\A[-a-z0-9]+\/[-a-z0-9]+\z}.freeze
|
|
|
|
end
|
|
|
|
|
2020-08-24 17:10:17 -04:00
|
|
|
def pypi_version_regex
|
|
|
|
# See the official regex: https://github.com/pypa/packaging/blob/16.7/packaging/version.py#L159
|
|
|
|
|
|
|
|
@pypi_version_regex ||= %r{
|
|
|
|
\A(?:
|
|
|
|
v?
|
|
|
|
(?:([0-9]+)!)? (?# epoch)
|
|
|
|
([0-9]+(?:\.[0-9]+)*) (?# release segment)
|
|
|
|
([-_\.]?((a|b|c|rc|alpha|beta|pre|preview))[-_\.]?([0-9]+)?)? (?# pre-release)
|
|
|
|
((?:-([0-9]+))|(?:[-_\.]?(post|rev|r)[-_\.]?([0-9]+)?))? (?# post release)
|
|
|
|
([-_\.]?(dev)[-_\.]?([0-9]+)?)? (?# dev release)
|
|
|
|
(?:\+([a-z0-9]+(?:[-_\.][a-z0-9]+)*))? (?# local version)
|
|
|
|
)\z}xi.freeze
|
|
|
|
end
|
|
|
|
|
2020-09-30 08:09:53 -04:00
|
|
|
def debian_package_name_regex
|
|
|
|
# See official parser
|
|
|
|
# https://git.dpkg.org/cgit/dpkg/dpkg.git/tree/lib/dpkg/parsehelp.c?id=9e0c88ec09475f4d1addde9cdba1ad7849720356#n122
|
|
|
|
# @debian_package_name_regex ||= %r{\A[a-z0-9][-+\._a-z0-9]*\z}i.freeze
|
|
|
|
# But we prefer a more strict version from Lintian
|
|
|
|
# https://salsa.debian.org/lintian/lintian/-/blob/5080c0068ffc4a9ddee92022a91d0c2ff53e56d1/lib/Lintian/Util.pm#L116
|
|
|
|
@debian_package_name_regex ||= %r{\A[a-z0-9][-+\.a-z0-9]+\z}.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def debian_version_regex
|
|
|
|
# See official parser: https://git.dpkg.org/cgit/dpkg/dpkg.git/tree/lib/dpkg/parsehelp.c?id=9e0c88ec09475f4d1addde9cdba1ad7849720356#n205
|
|
|
|
@debian_version_regex ||= %r{
|
|
|
|
\A(?:
|
|
|
|
(?:([0-9]{1,9}):)? (?# epoch)
|
|
|
|
([0-9][0-9a-z\.+~-]*) (?# version)
|
|
|
|
(?:(-[0-0a-z\.+~]+))? (?# revision)
|
|
|
|
)\z}xi.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def debian_architecture_regex
|
|
|
|
# See official parser: https://git.dpkg.org/cgit/dpkg/dpkg.git/tree/lib/dpkg/arch.c?id=9e0c88ec09475f4d1addde9cdba1ad7849720356#n43
|
|
|
|
# But we limit to lower case
|
2021-06-28 02:07:45 -04:00
|
|
|
@debian_architecture_regex ||= %r{\A#{::Packages::Debian::ARCHITECTURE_REGEX}\z}.freeze
|
2020-09-30 08:09:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def debian_distribution_regex
|
2021-06-28 02:07:45 -04:00
|
|
|
@debian_distribution_regex ||= %r{\A#{::Packages::Debian::DISTRIBUTION_REGEX}\z}i.freeze
|
2020-09-30 08:09:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def debian_component_regex
|
2021-06-28 02:07:45 -04:00
|
|
|
@debian_component_regex ||= %r{\A#{::Packages::Debian::COMPONENT_REGEX}\z}.freeze
|
2020-09-30 08:09:53 -04:00
|
|
|
end
|
|
|
|
|
2021-05-04 14:10:03 -04:00
|
|
|
def helm_channel_regex
|
2021-10-13 08:12:20 -04:00
|
|
|
@helm_channel_regex ||= %r{\A([a-zA-Z0-9](\.|-|_)?){1,255}(?<!\.|-|_)\z}.freeze
|
2021-05-04 14:10:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def helm_package_regex
|
|
|
|
@helm_package_regex ||= %r{#{helm_channel_regex}}.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def helm_version_regex
|
2021-06-15 05:10:21 -04:00
|
|
|
# identical to semver_regex, with optional preceding 'v'
|
|
|
|
@helm_version_regex ||= Regexp.new("\\Av?#{::Gitlab::Regex.unbounded_semver_regex.source}\\z", ::Gitlab::Regex.unbounded_semver_regex.options)
|
2021-05-04 14:10:03 -04:00
|
|
|
end
|
|
|
|
|
2020-06-10 05:08:35 -04:00
|
|
|
def unbounded_semver_regex
|
|
|
|
# See the official regex: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
|
|
|
|
|
|
|
# The order of the alternatives in <prerelease> are intentionally
|
|
|
|
# reordered to be greedy. Without this change, the unbounded regex would
|
|
|
|
# only partially match "v0.0.0-20201230123456-abcdefabcdef".
|
|
|
|
@unbounded_semver_regex ||= /
|
2020-10-06 17:09:22 -04:00
|
|
|
#{_semver_major_minor_patch_regex}#{_semver_prerelease_build_regex}
|
|
|
|
/x.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def semver_regex
|
2021-05-13 20:11:05 -04:00
|
|
|
@semver_regex ||= Regexp.new("\\A#{::Gitlab::Regex.unbounded_semver_regex.source}\\z", ::Gitlab::Regex.unbounded_semver_regex.options).freeze
|
2020-10-06 17:09:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# These partial semver regexes are intended for use in composing other
|
|
|
|
# regexes rather than being used alone.
|
|
|
|
def _semver_major_minor_patch_regex
|
|
|
|
@_semver_major_minor_patch_regex ||= /
|
2022-01-06 10:16:10 -05:00
|
|
|
#{_semver_major_regex}\.#{_semver_minor_regex}\.#{_semver_patch_regex}
|
|
|
|
/x.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def _semver_major_regex
|
|
|
|
@_semver_major_regex ||= /
|
2020-06-10 05:08:35 -04:00
|
|
|
(?<major>0|[1-9]\d*)
|
2022-01-06 10:16:10 -05:00
|
|
|
/x.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def _semver_minor_regex
|
|
|
|
@_semver_minor_regex ||= /
|
|
|
|
(?<minor>0|[1-9]\d*)
|
|
|
|
/x.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def _semver_patch_regex
|
|
|
|
@_semver_patch_regex ||= /
|
|
|
|
(?<patch>0|[1-9]\d*)
|
2020-06-10 05:08:35 -04:00
|
|
|
/x.freeze
|
|
|
|
end
|
|
|
|
|
2020-10-06 17:09:22 -04:00
|
|
|
def _semver_prerelease_build_regex
|
|
|
|
@_semver_prerelease_build_regex ||= /
|
|
|
|
(?:-(?<prerelease>(?:\d*[a-zA-Z-][0-9a-zA-Z-]*|[1-9]\d*|0)(?:\.(?:\d*[a-zA-Z-][0-9a-zA-Z-]*|[1-9]\d*|0))*))?
|
|
|
|
(?:\+(?<build>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?
|
|
|
|
/x.freeze
|
2020-06-10 05:08:35 -04:00
|
|
|
end
|
|
|
|
|
2020-09-22 11:09:37 -04:00
|
|
|
def prefixed_semver_regex
|
|
|
|
# identical to semver_regex, except starting with 'v'
|
|
|
|
@prefixed_semver_regex ||= Regexp.new("\\Av#{::Gitlab::Regex.unbounded_semver_regex.source}\\z", ::Gitlab::Regex.unbounded_semver_regex.options)
|
|
|
|
end
|
|
|
|
|
2020-06-10 05:08:35 -04:00
|
|
|
def go_package_regex
|
|
|
|
# A Go package name looks like a URL but is not; it:
|
|
|
|
# - Must not have a scheme, such as http:// or https://
|
|
|
|
# - Must not have a port number, such as :8080 or :8443
|
|
|
|
|
2021-07-28 11:09:57 -04:00
|
|
|
@go_package_regex ||= %r{
|
2020-06-10 05:08:35 -04:00
|
|
|
\b (?# word boundary)
|
|
|
|
(?<domain>
|
|
|
|
[0-9a-z](?:(?:-|[0-9a-z]){0,61}[0-9a-z])? (?# first domain)
|
|
|
|
(?:\.[0-9a-z](?:(?:-|[0-9a-z]){0,61}[0-9a-z])?)* (?# inner domains)
|
|
|
|
\.[a-z]{2,} (?# top-level domain)
|
|
|
|
)
|
2021-07-28 11:09:57 -04:00
|
|
|
(?<path>/(?:
|
|
|
|
[-/$_.+!*'(),0-9a-z] (?# plain URL character)
|
2020-06-10 05:08:35 -04:00
|
|
|
| %[0-9a-f]{2})* (?# URL encoded character)
|
|
|
|
)? (?# path)
|
|
|
|
\b (?# word boundary)
|
2021-07-28 11:09:57 -04:00
|
|
|
}ix.freeze
|
2020-06-09 08:08:55 -04:00
|
|
|
end
|
2020-09-01 17:10:21 -04:00
|
|
|
|
|
|
|
def generic_package_version_regex
|
2021-03-30 11:11:08 -04:00
|
|
|
maven_version_regex
|
2020-09-01 17:10:21 -04:00
|
|
|
end
|
2020-09-21 23:09:49 -04:00
|
|
|
|
2020-10-01 02:09:59 -04:00
|
|
|
def generic_package_name_regex
|
2020-09-21 23:09:49 -04:00
|
|
|
maven_file_name_regex
|
|
|
|
end
|
2020-10-01 02:09:59 -04:00
|
|
|
|
|
|
|
def generic_package_file_name_regex
|
|
|
|
generic_package_name_regex
|
|
|
|
end
|
2021-12-02 10:10:48 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def conan_name_regex
|
|
|
|
@conan_name_regex ||= %r{[a-zA-Z0-9_][a-zA-Z0-9_\+\.-]{1,49}}.freeze
|
|
|
|
end
|
2020-06-09 08:08:55 -04:00
|
|
|
end
|
|
|
|
|
2012-11-27 22:14:05 -05:00
|
|
|
extend self
|
2020-06-09 08:08:55 -04:00
|
|
|
extend Packages
|
2012-11-27 22:14:05 -05:00
|
|
|
|
2012-12-25 17:50:41 -05:00
|
|
|
def project_name_regex
|
2020-01-20 07:09:02 -05:00
|
|
|
# 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
|
2021-09-27 08:13:56 -04:00
|
|
|
@project_name_regex ||= /\A[\p{Alnum}\u{00A9}-\u{1f9ff}_][\p{Alnum}\p{Pd}\u{002B}\u{00A9}-\u{1f9ff}_\. ]*\z/.freeze
|
2012-12-25 17:50:41 -05:00
|
|
|
end
|
|
|
|
|
2015-03-24 09:55:14 -04:00
|
|
|
def project_name_regex_message
|
2021-09-27 08:13:56 -04:00
|
|
|
"can contain only letters, digits, emojis, '_', '.', '+', dashes, or spaces. " \
|
|
|
|
"It must start with a letter, digit, emoji, or '_'."
|
2014-06-26 03:53:01 -04:00
|
|
|
end
|
|
|
|
|
2022-03-04 10:16:11 -05:00
|
|
|
# Project path must conform to this regex. See https://gitlab.com/gitlab-org/gitlab/-/issues/27483
|
|
|
|
def oci_repository_path_regex
|
|
|
|
@oci_repository_path_regex ||= %r{\A[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*\z}.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def oci_repository_path_regex_message
|
|
|
|
'must not start or end with a special character and must not contain consecutive special characters.'
|
|
|
|
end
|
|
|
|
|
2020-03-26 14:08:03 -04:00
|
|
|
def group_name_regex
|
2020-08-25 08:04:30 -04:00
|
|
|
@group_name_regex ||= /\A#{group_name_regex_chars}\z/.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_name_regex_chars
|
|
|
|
@group_name_regex_chars ||= /[\p{Alnum}\u{00A9}-\u{1f9ff}_][\p{Alnum}\p{Pd}\u{00A9}-\u{1f9ff}_()\. ]*/.freeze
|
2020-03-26 14:08:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def group_name_regex_message
|
2020-03-30 14:08:07 -04:00
|
|
|
"can contain only letters, digits, emojis, '_', '.', dash, space, parenthesis. " \
|
|
|
|
"It must start with letter, digit, emoji or '_'."
|
2020-03-26 14:08:03 -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
|
2020-11-02 16:09:10 -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
|
2021-04-26 14:09:45 -04:00
|
|
|
@container_registry_tag_regex ||= /\w[\w.-]{0,127}/
|
2017-07-19 04:30:57 -04:00
|
|
|
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
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
# https://gitlab.com/gitlab-org/cluster-integration/gitlab-agent/-/blob/master/doc/identity_and_auth.md#agent-identity-and-name
|
|
|
|
def cluster_agent_name_regex
|
|
|
|
/\A[a-z0-9]([-a-z0-9]*[a-z0-9])?\z/
|
|
|
|
end
|
|
|
|
|
|
|
|
def cluster_agent_name_regex_message
|
|
|
|
%q{can contain only lowercase letters, digits, and '-', but cannot start or end with '-'}
|
|
|
|
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
|
|
|
|
2020-05-07 05:09:51 -04:00
|
|
|
# Pod name adheres to DNS Subdomain Names(RFC 1123) naming convention
|
|
|
|
# https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
|
|
|
|
def kubernetes_dns_subdomain_regex
|
|
|
|
/\A[a-z0-9]([a-z0-9\-\.]*[a-z0-9])?\z/
|
|
|
|
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
|
|
|
|
2020-09-24 11:09:51 -04:00
|
|
|
# The section start, e.g. section_start:12345678:NAME
|
|
|
|
def logs_section_prefix_regex
|
|
|
|
/section_((?:start)|(?:end)):(\d+):([a-zA-Z0-9_.-]+)/
|
|
|
|
end
|
|
|
|
|
|
|
|
# The optional section options, e.g. [collapsed=true]
|
|
|
|
def logs_section_options_regex
|
|
|
|
/(\[(?:\w+=\w+)(?:, ?(?:\w+=\w+))*\])?/
|
|
|
|
end
|
|
|
|
|
|
|
|
# The region end, always: \r\e\[0K
|
|
|
|
def logs_section_suffix_regex
|
|
|
|
/\r\033\[0K/
|
|
|
|
end
|
|
|
|
|
2017-09-25 12:54:08 -04:00
|
|
|
def build_trace_section_regex
|
2020-09-24 11:09:51 -04:00
|
|
|
@build_trace_section_regexp ||= %r{
|
|
|
|
#{logs_section_prefix_regex}
|
|
|
|
#{logs_section_options_regex}
|
|
|
|
#{logs_section_suffix_regex}
|
|
|
|
}x.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
|
2020-04-21 11:21:10 -04:00
|
|
|
@jira_issue_key_regex ||= /[A-Z][A-Z_0-9]+-\d+/
|
2019-07-25 05:29:51 -04:00
|
|
|
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
|
2020-02-18 07:09:15 -05:00
|
|
|
|
2020-07-08 17:09:09 -04:00
|
|
|
def merge_request_draft
|
2021-10-13 14:12:40 -04:00
|
|
|
/\A(?i)(\[draft\]|\(draft\)|draft:)/
|
2020-07-08 17:09:09 -04:00
|
|
|
end
|
|
|
|
|
2020-02-18 07:09:15 -05:00
|
|
|
def issue
|
2021-11-24 07:10:21 -05:00
|
|
|
@issue ||= /(?<issue>\d+)(?<format>\+)?(?=\W|\z)/
|
2020-02-18 07:09:15 -05:00
|
|
|
end
|
2020-06-10 05:08:35 -04:00
|
|
|
|
2021-12-06 19:14:07 -05:00
|
|
|
def merge_request
|
|
|
|
@merge_request ||= /(?<merge_request>\d+)(?<format>\+)?/
|
|
|
|
end
|
|
|
|
|
2020-06-10 05:08:35 -04:00
|
|
|
def base64_regex
|
2021-07-28 11:09:57 -04:00
|
|
|
@base64_regex ||= %r{(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?}.freeze
|
2020-06-10 05:08:35 -04:00
|
|
|
end
|
2020-09-03 17:08:18 -04:00
|
|
|
|
|
|
|
def feature_flag_regex
|
|
|
|
/\A[a-z]([-_a-z0-9]*[a-z0-9])?\z/
|
|
|
|
end
|
|
|
|
|
|
|
|
def feature_flag_regex_message
|
|
|
|
"can contain only lowercase letters, digits, '_' and '-'. " \
|
|
|
|
"Must start with a letter, and cannot end with '-' or '_'"
|
|
|
|
end
|
2022-03-03 13:19:46 -05:00
|
|
|
|
|
|
|
def saved_reply_name_regex
|
|
|
|
@saved_reply_name_regex ||= /\A[a-z]([a-z0-9\-_]*[a-z0-9])?\z/.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def saved_reply_name_regex_message
|
|
|
|
"can contain only lowercase letters, digits, '_' and '-'. " \
|
|
|
|
"Must start with a letter, and cannot end with '-' or '_'"
|
|
|
|
end
|
2012-11-27 22:14:05 -05:00
|
|
|
end
|
|
|
|
end
|
2021-12-06 19:14:07 -05:00
|
|
|
|
|
|
|
Gitlab::Regex.prepend_mod
|