Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bulk_imports.rb « regex « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e9ec24b831fb781671cdbc858d04498f25b293f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

module Gitlab
  module Regex
    module BulkImports
      def bulk_import_destination_namespace_path_regex
        # This regexp validates the string conforms to rules for a destination_namespace path:
        # i.e does not start with a non-alphanumeric character,
        # contains only alphanumeric characters, forward slashes, periods, and underscores,
        # does not end with a period or forward slash, and has a relative path structure
        # with no http protocol chars or leading or trailing forward slashes
        # eg 'source/full/path' or 'destination_namespace' not 'https://example.com/destination/namespace/path'
        # the regex also allows for an empty string ('') to be accepted as this is allowed in
        # a bulk_import POST request
        @bulk_import_destination_namespace_path_regex ||= %r/((\A\z)|(\A[0-9a-z]*(-_.)?[0-9a-z])(\/?[0-9a-z]*[-_.]?[0-9a-z])+\z)/i
      end

      def bulk_import_source_full_path_regex
        # This regexp validates the string conforms to rules for a source_full_path path:
        # i.e does not start with a non-alphanumeric character except for periods or underscores,
        # contains only alphanumeric characters, forward slashes, periods, and underscores,
        # does not end with a period or forward slash, and has a relative path structure
        # with no http protocol chars or leading or trailing forward slashes
        # eg 'source/full/path' or 'destination_namespace' not 'https://example.com/source/full/path'
        @bulk_import_source_full_path_regex ||= %r/\A([.]?)[^\W](\/?([-_.+]*)*[0-9a-z][-_]*)+\z/i
      end

      def bulk_import_source_full_path_regex_message
        bulk_import_destination_namespace_path_regex_message
      end

      def bulk_import_destination_namespace_path_regex_message
        "must have a relative path structure " \
        "with no HTTP protocol characters, or leading or trailing forward slashes. " \
        "Path segments must not start or end with a special character, " \
        "and must not contain consecutive special characters."
      end
    end
  end
end