Module: Gitlab::Regex

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

Constant Summary collapse

NAMESPACE_REGEX_STR =
'(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])'.freeze

Instance Method Summary collapse

Instance Method Details

#archive_formats_regexObject


72
73
74
75
# File 'lib/gitlab/regex.rb', line 72

def archive_formats_regex
  #                           |zip|tar|    tar.gz    |         tar.bz2         |
  @archive_formats_regex ||= /(zip|tar|tar\.gz|tgz|gz|tar\.bz2|tbz|tbz2|tb2|bz2)/.freeze
end

#directory_traversal_regexObject


63
64
65
# File 'lib/gitlab/regex.rb', line 63

def directory_traversal_regex
  @directory_traversal_regex ||= /\.{2}/.freeze
end

#directory_traversal_regex_messageObject


67
68
69
# File 'lib/gitlab/regex.rb', line 67

def directory_traversal_regex_message
  "cannot include directory traversal. "
end

#file_name_regexObject


46
47
48
# File 'lib/gitlab/regex.rb', line 46

def file_name_regex
  @file_name_regex ||= /\A[a-zA-Z0-9_\-\.\@]*\z/.freeze
end

#file_name_regex_messageObject


50
51
52
# File 'lib/gitlab/regex.rb', line 50

def file_name_regex_message
  "can contain only letters, digits, '_', '-', '@' and '.'. "
end

#file_path_regexObject


54
55
56
# File 'lib/gitlab/regex.rb', line 54

def file_path_regex
  @file_path_regex ||= /\A[a-zA-Z0-9_\-\.\/\@]*\z/.freeze
end

#file_path_regex_messageObject


58
59
60
# File 'lib/gitlab/regex.rb', line 58

def file_path_regex_message
  "can contain only letters, digits, '_', '-', '@' and '.'. Separate directories with a '/'. "
end

#git_reference_regexObject


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/gitlab/regex.rb', line 77

def git_reference_regex
  # Valid git ref regex, see:
  # https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html

  @git_reference_regex ||= %r{
    (?!
       (?# doesn't begins with)
       \/|                    (?# rule #6)
       (?# doesn't contain)
       .*(?:
          [\/.]\.|            (?# rule #1,3)
          \/\/|               (?# rule #6)
          @\{|                (?# rule #8)
          \\                  (?# rule #9)
       )
    )
    [^\000-\040\177~^:?*\[]+  (?# rule #4-5)
    (?# doesn't end with)
    (?<!\.lock)               (?# rule #1)
    (?<![\/.])                (?# rule #6-7)
  }x.freeze
end

#namespace_name_regexObject


17
18
19
# File 'lib/gitlab/regex.rb', line 17

def namespace_name_regex
  @namespace_name_regex ||= /\A[\p{Alnum}\p{Pd}_\. ]*\z/.freeze
end

#namespace_name_regex_messageObject


21
22
23
# File 'lib/gitlab/regex.rb', line 21

def namespace_name_regex_message
  "can contain only letters, digits, '_', '.', dash and space."
end

#namespace_regexObject


7
8
9
# File 'lib/gitlab/regex.rb', line 7

def namespace_regex
  @namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze
end

#namespace_regex_messageObject


11
12
13
14
# File 'lib/gitlab/regex.rb', line 11

def namespace_regex_message
  "can contain only letters, digits, '_', '-' and '.'. " \
  "Cannot start with '-' or end in '.'." \
end

#project_name_regexObject


26
27
28
# File 'lib/gitlab/regex.rb', line 26

def project_name_regex
  @project_name_regex ||= /\A[\p{Alnum}_][\p{Alnum}\p{Pd}_\. ]*\z/.freeze
end

#project_name_regex_messageObject


30
31
32
33
# File 'lib/gitlab/regex.rb', line 30

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

#project_path_regexObject


36
37
38
# File 'lib/gitlab/regex.rb', line 36

def project_path_regex
  @project_path_regex ||= /\A[a-zA-Z0-9_.][a-zA-Z0-9_\-\.]*(?<!\.git|\.atom)\z/.freeze
end

#project_path_regex_messageObject


40
41
42
43
# File 'lib/gitlab/regex.rb', line 40

def project_path_regex_message
  "can contain only letters, digits, '_', '-' and '.'. " \
  "Cannot start with '-', end in '.git' or end in '.atom'" \
end