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::CONAN_PACKAGE_FILES, Packages::CONAN_RECIPE_FILES

Instance Method Summary collapse

Methods included from Packages

composer_package_version_regex, conan_package_reference_regex, conan_recipe_component_regex, conan_revision_regex, generic_package_version_regex, go_package_regex, maven_app_group_regex, maven_app_name_regex, maven_file_name_regex, maven_path_regex, maven_version_regex, package_name_regex, pypi_version_regex, semver_regex, unbounded_semver_regex

Instance Method Details

#aws_account_id_messageObject


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

def 
  'must be a 12-digit number'
end

#aws_account_id_regexObject


259
260
261
# File 'lib/gitlab/regex.rb', line 259

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

#aws_arn_regexObject


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

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

#aws_arn_regex_messageObject


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

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

#base64_regexObject


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

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

#breakline_regexObject


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

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

#build_trace_section_regexObject


214
215
216
# File 'lib/gitlab/regex.rb', line 214

def build_trace_section_regex
  @build_trace_section_regexp ||= /section_((?:start)|(?:end)):(\d+):([a-zA-Z0-9_.-]+)\r\033\[0K/.freeze
end

#cluster_agent_name_regexObject


182
183
184
# File 'lib/gitlab/regex.rb', line 182

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

#cluster_agent_name_regex_messageObject


186
187
188
# File 'lib/gitlab/regex.rb', line 186

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.


149
150
151
# File 'lib/gitlab/regex.rb', line 149

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.


141
142
143
# File 'lib/gitlab/regex.rb', line 141

def container_repository_name_regex
  @container_repository_regex ||= %r{\A[a-z0-9]+((?:[._/]|__|[-]{0,10})[a-z0-9]+)*\Z}
end

#environment_name_regexObject


161
162
163
# File 'lib/gitlab/regex.rb', line 161

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


153
154
155
# File 'lib/gitlab/regex.rb', line 153

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

#environment_name_regex_chars_without_slashObject


157
158
159
# File 'lib/gitlab/regex.rb', line 157

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

#environment_name_regex_messageObject


165
166
167
# File 'lib/gitlab/regex.rb', line 165

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

#environment_scope_regexObject


173
174
175
# File 'lib/gitlab/regex.rb', line 173

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

#environment_scope_regex_charsObject


169
170
171
# File 'lib/gitlab/regex.rb', line 169

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

#environment_scope_regex_messageObject


177
178
179
# File 'lib/gitlab/regex.rb', line 177

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

#environment_slug_regexObject


205
206
207
# File 'lib/gitlab/regex.rb', line 205

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

#environment_slug_regex_messageObject


209
210
211
212
# File 'lib/gitlab/regex.rb', line 209

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


296
297
298
# File 'lib/gitlab/regex.rb', line 296

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

#feature_flag_regex_messageObject


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

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


123
124
125
# File 'lib/gitlab/regex.rb', line 123

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

#group_name_regex_charsObject


127
128
129
# File 'lib/gitlab/regex.rb', line 127

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


131
132
133
134
# File 'lib/gitlab/regex.rb', line 131

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

#issueObject


288
289
290
# File 'lib/gitlab/regex.rb', line 288

def issue
  @issue ||= /(?<issue>\d+\b)/
end

#jira_issue_key_regexObject


246
247
248
# File 'lib/gitlab/regex.rb', line 246

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

#jira_transition_id_regexObject


250
251
252
# File 'lib/gitlab/regex.rb', line 250

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


201
202
203
# File 'lib/gitlab/regex.rb', line 201

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

#kubernetes_namespace_regexObject


190
191
192
# File 'lib/gitlab/regex.rb', line 190

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

#kubernetes_namespace_regex_messageObject


194
195
196
197
# File 'lib/gitlab/regex.rb', line 194

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

#markdown_code_or_html_blocksObject


218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/gitlab/regex.rb', line 218

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_request_draftObject


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

def merge_request_draft
  /(?i)(\[draft\]|\(draft\)|draft:|draft\s\-\s|draft$)/
end

#merge_request_wipObject


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

def merge_request_wip
  /(?i)(\[WIP\]\s*|WIP:\s*|WIP$)/
end

#project_name_regexObject


111
112
113
114
115
116
# File 'lib/gitlab/regex.rb', line 111

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{00A9}-\u{1f9ff}_\. ]*\z/.freeze
end

#project_name_regex_messageObject


118
119
120
121
# File 'lib/gitlab/regex.rb', line 118

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

#utc_date_regexObject


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

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