Module: Gitlab::Regex

Extended by:
Regex, Packages
Included in:
Regex
Defined in:
lib/gitlab/regex.rb

Defined Under Namespace

Modules: Packages

Constant Summary

Constants included from Packages

Packages::API_PATH_REGEX, Packages::CONAN_PACKAGE_FILES, Packages::CONAN_RECIPE_FILES

Instance Method Summary collapse

Methods included from Packages

_semver_major_minor_patch_regex, _semver_major_regex, _semver_minor_regex, _semver_patch_regex, _semver_prerelease_build_regex, composer_dev_version_regex, composer_package_version_regex, conan_package_reference_regex, conan_recipe_component_regex, conan_recipe_user_channel_regex, conan_revision_regex, debian_architecture_regex, debian_component_regex, debian_distribution_regex, debian_package_name_regex, debian_version_regex, generic_package_file_name_regex, generic_package_name_regex, generic_package_version_regex, go_package_regex, helm_channel_regex, helm_package_regex, helm_version_regex, maven_app_group_regex, maven_app_name_regex, maven_file_name_regex, maven_path_regex, maven_version_regex, npm_package_name_regex, nuget_package_name_regex, nuget_version_regex, package_name_regex, prefixed_semver_regex, pypi_version_regex, semver_regex, sha256_regex, terraform_module_package_name_regex, unbounded_semver_regex

Instance Method Details

#aws_account_id_messageObject


434
435
436
# File 'lib/gitlab/regex.rb', line 434

def 
  'must be a 12-digit number'
end

#aws_account_id_regexObject


430
431
432
# File 'lib/gitlab/regex.rb', line 430

def 
  /\A\d{12}\z/
end

#aws_arn_regexObject


439
440
441
# File 'lib/gitlab/regex.rb', line 439

def aws_arn_regex
  /\Aarn:\S+\z/
end

#aws_arn_regex_messageObject


443
444
445
# File 'lib/gitlab/regex.rb', line 443

def aws_arn_regex_message
  'must be a valid Amazon Resource Name'
end

#base64_regexObject


463
464
465
# File 'lib/gitlab/regex.rb', line 463

def base64_regex
  @base64_regex ||= %r{(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?}.freeze
end

#breakline_regexObject


425
426
427
# File 'lib/gitlab/regex.rb', line 425

def breakline_regex
  @breakline_regex ||= /\r\n|\r|\n/
end

#build_trace_section_regexObject


381
382
383
384
385
386
387
# File 'lib/gitlab/regex.rb', line 381

def build_trace_section_regex
  @build_trace_section_regexp ||= %r{
    #{logs_section_prefix_regex}
    #{logs_section_options_regex}
    #{logs_section_suffix_regex}
  }x.freeze
end

#cluster_agent_name_regexObject


334
335
336
# File 'lib/gitlab/regex.rb', line 334

def cluster_agent_name_regex
  /\A[a-z0-9]([-a-z0-9]*[a-z0-9])?\z/
end

#cluster_agent_name_regex_messageObject


338
339
340
# File 'lib/gitlab/regex.rb', line 338

def cluster_agent_name_regex_message
  %q{can contain only lowercase letters, digits, and '-', but cannot start or end with '-'}
end

#container_registry_tag_regexObject

We do not use regexp anchors here because these are not allowed when used as a routing constraint.


301
302
303
# File 'lib/gitlab/regex.rb', line 301

def container_registry_tag_regex
  @container_registry_tag_regex ||= /\w[\w.-]{0,127}/
end

#container_repository_name_regexObject

Docker Distribution Registry repository / tag name rules

See github.com/docker/distribution/blob/master/reference/regexp.go.


293
294
295
# File 'lib/gitlab/regex.rb', line 293

def container_repository_name_regex
  @container_repository_regex ||= %r{\A[a-z0-9]+(([._/]|__|-*)[a-z0-9])*\z}
end

#environment_name_regexObject


313
314
315
# File 'lib/gitlab/regex.rb', line 313

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
end

#environment_name_regex_charsObject


305
306
307
# File 'lib/gitlab/regex.rb', line 305

def environment_name_regex_chars
  'a-zA-Z0-9_/\\$\\{\\}\\. \\-'
end

#environment_name_regex_chars_without_slashObject


309
310
311
# File 'lib/gitlab/regex.rb', line 309

def environment_name_regex_chars_without_slash
  'a-zA-Z0-9_\\$\\{\\}\\. -'
end

#environment_name_regex_messageObject


317
318
319
# File 'lib/gitlab/regex.rb', line 317

def environment_name_regex_message
  "can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', and spaces, but it cannot start or end with '/'"
end

#environment_scope_regexObject


325
326
327
# File 'lib/gitlab/regex.rb', line 325

def environment_scope_regex
  @environment_scope_regex ||= /\A[#{environment_scope_regex_chars}]+\z/.freeze
end

#environment_scope_regex_charsObject


321
322
323
# File 'lib/gitlab/regex.rb', line 321

def environment_scope_regex_chars
  "#{environment_name_regex_chars}\\*"
end

#environment_scope_regex_messageObject


329
330
331
# File 'lib/gitlab/regex.rb', line 329

def environment_scope_regex_message
  "can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', '*' and spaces"
end

#environment_slug_regexObject


357
358
359
# File 'lib/gitlab/regex.rb', line 357

def environment_slug_regex
  @environment_slug_regex ||= /\A[a-z]([a-z0-9-]*[a-z0-9])?\z/.freeze
end

#environment_slug_regex_messageObject


361
362
363
364
# File 'lib/gitlab/regex.rb', line 361

def environment_slug_regex_message
  "can contain only lowercase letters, digits, and '-'. " \
  "Must start with a letter, and cannot end with '-'"
end

#feature_flag_regexObject


467
468
469
# File 'lib/gitlab/regex.rb', line 467

def feature_flag_regex
  /\A[a-z]([-_a-z0-9]*[a-z0-9])?\z/
end

#feature_flag_regex_messageObject


471
472
473
474
# File 'lib/gitlab/regex.rb', line 471

def feature_flag_regex_message
  "can contain only lowercase letters, digits, '_' and '-'. " \
  "Must start with a letter, and cannot end with '-' or '_'"
end

#group_name_regexObject


275
276
277
# File 'lib/gitlab/regex.rb', line 275

def group_name_regex
  @group_name_regex ||= /\A#{group_name_regex_chars}\z/.freeze
end

#group_name_regex_charsObject


279
280
281
# File 'lib/gitlab/regex.rb', line 279

def group_name_regex_chars
  @group_name_regex_chars ||= /[\p{Alnum}\u{00A9}-\u{1f9ff}_][\p{Alnum}\p{Pd}\u{00A9}-\u{1f9ff}_()\. ]*/.freeze
end

#group_name_regex_messageObject


283
284
285
286
# File 'lib/gitlab/regex.rb', line 283

def group_name_regex_message
  "can contain only letters, digits, emojis, '_', '.', dash, space, parenthesis. " \
  "It must start with letter, digit, emoji or '_'."
end

#issueObject


455
456
457
# File 'lib/gitlab/regex.rb', line 455

def issue
  @issue ||= /(?<issue>\d+)(?<format>\+)?(?=\W|\z)/
end

#jira_issue_key_regexObject


417
418
419
# File 'lib/gitlab/regex.rb', line 417

def jira_issue_key_regex
  @jira_issue_key_regex ||= /[A-Z][A-Z_0-9]+-\d+/
end

#jira_transition_id_regexObject


421
422
423
# File 'lib/gitlab/regex.rb', line 421

def jira_transition_id_regex
  @jira_transition_id_regex ||= /\d+/
end

#kubernetes_dns_subdomain_regexObject

Pod name adheres to DNS Subdomain Names(RFC 1123) naming convention kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names


353
354
355
# File 'lib/gitlab/regex.rb', line 353

def kubernetes_dns_subdomain_regex
  /\A[a-z0-9]([a-z0-9\-\.]*[a-z0-9])?\z/
end

#kubernetes_namespace_regexObject


342
343
344
# File 'lib/gitlab/regex.rb', line 342

def kubernetes_namespace_regex
  /\A[a-z0-9]([-a-z0-9]*[a-z0-9])?\z/
end

#kubernetes_namespace_regex_messageObject


346
347
348
349
# File 'lib/gitlab/regex.rb', line 346

def kubernetes_namespace_regex_message
  "can contain only lowercase letters, digits, and '-'. " \
  "Must start with a letter, and cannot end with '-'"
end

#logs_section_options_regexObject

The optional section options, e.g. [collapsed=true]


372
373
374
# File 'lib/gitlab/regex.rb', line 372

def logs_section_options_regex
  /(\[(?:\w+=\w+)(?:, ?(?:\w+=\w+))*\])?/
end

#logs_section_prefix_regexObject

The section start, e.g. section_start:12345678:NAME


367
368
369
# File 'lib/gitlab/regex.rb', line 367

def logs_section_prefix_regex
  /section_((?:start)|(?:end)):(\d+):([a-zA-Z0-9_.-]+)/
end

#logs_section_suffix_regexObject

The region end, always: re[0K


377
378
379
# File 'lib/gitlab/regex.rb', line 377

def logs_section_suffix_regex
  /\r\033\[0K/
end

#markdown_code_or_html_blocksObject


389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/gitlab/regex.rb', line 389

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

#merge_requestObject


459
460
461
# File 'lib/gitlab/regex.rb', line 459

def merge_request
  @merge_request ||= /(?<merge_request>\d+)(?<format>\+)?/
end

#merge_request_draftObject


451
452
453
# File 'lib/gitlab/regex.rb', line 451

def merge_request_draft
  /\A(?i)(\[draft\]|\(draft\)|draft:)/
end

#oci_repository_path_regexObject

Project path must conform to this regex. See gitlab.com/gitlab-org/gitlab/-/issues/27483


267
268
269
# File 'lib/gitlab/regex.rb', line 267

def oci_repository_path_regex
  @oci_repository_path_regex ||= %r{\A[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*\z}.freeze
end

#oci_repository_path_regex_messageObject


271
272
273
# File 'lib/gitlab/regex.rb', line 271

def oci_repository_path_regex_message
  'must not start or end with a special character and must not contain consecutive special characters.'
end

#project_name_regexObject


254
255
256
257
258
259
# File 'lib/gitlab/regex.rb', line 254

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
end

#project_name_regex_messageObject


261
262
263
264
# File 'lib/gitlab/regex.rb', line 261

def project_name_regex_message
  "can contain only letters, digits, emojis, '_', '.', '+', dashes, or spaces. " \
  "It must start with a letter, digit, emoji, or '_'."
end

#saved_reply_name_regexObject


476
477
478
# File 'lib/gitlab/regex.rb', line 476

def saved_reply_name_regex
  @saved_reply_name_regex ||= /\A[a-z]([a-z0-9\-_]*[a-z0-9])?\z/.freeze
end

#saved_reply_name_regex_messageObject


480
481
482
483
# File 'lib/gitlab/regex.rb', line 480

def saved_reply_name_regex_message
  "can contain only lowercase letters, digits, '_' and '-'. " \
  "Must start with a letter, and cannot end with '-' or '_'"
end

#utc_date_regexObject


447
448
449
# File 'lib/gitlab/regex.rb', line 447

def utc_date_regex
  @utc_date_regex ||= /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/.freeze
end