regex.rb 1.23 KB
Newer Older
1 2 3 4 5 6 7 8
module Gitlab
  module Regex
    extend self

    def username_regex
      default_regex
    end

9
    def project_name_regex
10
      /\A[a-zA-Z0-9][a-zA-Z0-9_\-\. ]*\z/
11 12
    end

13 14 15 16
    def name_regex
      /\A[a-zA-Z0-9_\-\. ]*\z/
    end

17 18 19
    def path_regex
      default_regex
    end
20

21 22 23 24
    def archive_formats_regex
      #|zip|tar|    tar.gz    |         tar.bz2         |
      /(zip|tar|tar\.gz|tgz|gz|tar\.bz2|tbz|tbz2|tb2|bz2)/
    end
25

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

      %r{
        (?!
32 33 34
           (?# doesn't begins with)
           \/|                    (?# rule #6)
           (?# doesn't contain)
35
           .*(?:
36 37 38 39
              [\/.]\.|            (?# rule #1,3)
              \/\/|               (?# rule #6)
              @\{|                (?# rule #8)
              \\                  (?# rule #9)
40 41
           )
        )
42 43 44 45
        [^\000-\040\177~^:?*\[]+  (?# rule #4-5)
        (?# doesn't end with)
        (?<!\.lock)               (?# rule #1)
        (?<![\/.])                (?# rule #6-7)
46 47 48
      }x
    end

49 50 51
    protected

    def default_regex
52
      /\A[.?]?[a-zA-Z0-9][a-zA-Z0-9_\-\.]*(?<!\.git)\z/
53 54 55
    end
  end
end