diff options
Diffstat (limited to 'lib/gitlab/regex.rb')
-rw-r--r-- | lib/gitlab/regex.rb | 51 |
1 files changed, 18 insertions, 33 deletions
diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index 8ef455efe07..2fd9dc9fa09 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -6,26 +6,11 @@ module Gitlab extend MergeRequests extend Packages - def group_path_regex - # This regexp validates the string conforms to rules for a group slug: - # i.e does not start with a non-alphanumeric character except for periods or underscores, - # contains only alphanumeric characters, periods, and underscores, - # does not end with a period or forward slash, and has no leading or trailing forward slashes - # eg 'destination-path' or 'destination_pth' not 'example/com/destination/full/path' - @group_path_regex ||= %r{\A[.]?[^\W]([.]?[0-9a-z][-_]*)+\z}i - end - - def group_path_regex_message - "cannot start with a non-alphanumeric character except for periods or underscores, " \ - "can contain only alphanumeric characters, periods, and underscores, " \ - "cannot end with a period or forward slash, and has no leading or trailing forward slashes." \ - end - def project_name_regex # 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{002B}\u{00A9}-\u{1f9ff}_\. ]*\z/.freeze + @project_name_regex ||= /\A[\p{Alnum}\u{00A9}-\u{1f9ff}_][\p{Alnum}\p{Pd}\u{002B}\u{00A9}-\u{1f9ff}_\. ]*\z/ end def project_name_regex_message @@ -35,7 +20,7 @@ module Gitlab # 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 + @oci_repository_path_regex ||= %r{\A[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*\z} end def oci_repository_path_regex_message @@ -43,11 +28,11 @@ module Gitlab end def group_name_regex - @group_name_regex ||= /\A#{group_name_regex_chars}\z/.freeze + @group_name_regex ||= /\A#{group_name_regex_chars}\z/ 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 + @group_name_regex_chars ||= /[\p{Alnum}\u{00A9}-\u{1f9ff}_][\p{Alnum}\p{Pd}\u{00A9}-\u{1f9ff}_()\. ]*/ end def group_name_regex_message @@ -81,7 +66,7 @@ module Gitlab end def environment_name_regex - @environment_name_regex ||= /\A[#{environment_name_regex_chars_without_slash}]([#{environment_name_regex_chars}]*[#{environment_name_regex_chars_without_slash}])?\z/.freeze + @environment_name_regex ||= /\A[#{environment_name_regex_chars_without_slash}]([#{environment_name_regex_chars}]*[#{environment_name_regex_chars_without_slash}])?\z/ end def environment_name_regex_message @@ -93,7 +78,7 @@ module Gitlab end def environment_scope_regex - @environment_scope_regex ||= /\A[#{environment_scope_regex_chars}]+\z/.freeze + @environment_scope_regex ||= /\A[#{environment_scope_regex_chars}]+\z/ end def environment_scope_regex_message @@ -125,7 +110,7 @@ module Gitlab end def environment_slug_regex - @environment_slug_regex ||= /\A[a-z]([a-z0-9-]*[a-z0-9])?\z/.freeze + @environment_slug_regex ||= /\A[a-z]([a-z0-9-]*[a-z0-9])?\z/ end def environment_slug_regex_message @@ -153,7 +138,7 @@ module Gitlab #{logs_section_prefix_regex} #{logs_section_options_regex} #{logs_section_suffix_regex} - }x.freeze + }x end MARKDOWN_CODE_BLOCK_REGEX = %r{ @@ -167,7 +152,7 @@ module Gitlab .+? \n```\ *$ ) - }mx.freeze + }mx # Code blocks: # ``` @@ -178,7 +163,7 @@ module Gitlab '^```.*?\n' \ '(?:\n|.)*?' \ '\n```\ *$' \ - ')'.freeze + ')' MARKDOWN_HTML_BLOCK_REGEX = %r{ (?<html> @@ -191,7 +176,7 @@ module Gitlab .+? \n<\/[^>]+?>\ *$ ) - }mx.freeze + }mx # HTML block: # <tag> @@ -202,28 +187,28 @@ module Gitlab '^<[^>]+?>\ *\n' \ '(?:\n|.)*?' \ '\n<\/[^>]+?>\ *$' \ - ')'.freeze + ')' # HTML comment line: # <!-- some commented text --> MARKDOWN_HTML_COMMENT_LINE_REGEX_UNTRUSTED = '(?P<html_comment_line>' \ '^<!--\ .*?\ -->\ *$' \ - ')'.freeze + ')' MARKDOWN_HTML_COMMENT_BLOCK_REGEX_UNTRUSTED = '(?P<html_comment_block>' \ '^<!--.*?\n' \ '(?:\n|.)*?' \ '\n.*?-->\ *$' \ - ')'.freeze + ')' def markdown_code_or_html_blocks @markdown_code_or_html_blocks ||= %r{ #{MARKDOWN_CODE_BLOCK_REGEX} | #{MARKDOWN_HTML_BLOCK_REGEX} - }mx.freeze + }mx end def markdown_code_or_html_blocks_untrusted @@ -292,7 +277,7 @@ module Gitlab end def utc_date_regex - @utc_date_regex ||= /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/.freeze + @utc_date_regex ||= /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/ end def issue @@ -304,7 +289,7 @@ module Gitlab end def base64_regex - @base64_regex ||= %r{(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?}.freeze + @base64_regex ||= %r{(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?} end def feature_flag_regex @@ -317,7 +302,7 @@ module Gitlab end def x509_subject_key_identifier_regex - @x509_subject_key_identifier_regex ||= /\A(?:\h{2}:)*\h{2}\z/.freeze + @x509_subject_key_identifier_regex ||= /\A(?:\h{2}:)*\h{2}\z/ end def ml_model_name_regex |