diff options
Diffstat (limited to 'lib/api/validations/validators/bulk_imports.rb')
-rw-r--r-- | lib/api/validations/validators/bulk_imports.rb | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/lib/api/validations/validators/bulk_imports.rb b/lib/api/validations/validators/bulk_imports.rb index 4625f2f39cd..bff3424a0ac 100644 --- a/lib/api/validations/validators/bulk_imports.rb +++ b/lib/api/validations/validators/bulk_imports.rb @@ -6,13 +6,25 @@ module API module BulkImports class DestinationSlugPath < Grape::Validations::Base def validate_param!(attr_name, params) - unless params[attr_name] =~ Gitlab::Regex.group_path_regex # rubocop: disable Style/GuardClause + if Feature.disabled?(:restrict_special_characters_in_namespace_path) + return if params[attr_name] =~ Gitlab::Regex.group_path_regex + raise Grape::Exceptions::Validation.new( params: [@scope.full_name(attr_name)], - message: "cannot start with a dash or forward slash, or end with a period or forward slash. " \ + message: "#{Gitlab::Regex.group_path_regex_message} " \ "It can only contain alphanumeric characters, periods, underscores, and dashes. " \ - "E.g. 'destination_namespace' not 'destination/namespace'" + "For example, 'destination_namespace' not 'destination/namespace'" ) + else + return if params[attr_name] =~ Gitlab::Regex.oci_repository_path_regex + + raise Grape::Exceptions::Validation.new( + params: [@scope.full_name(attr_name)], + message: "#{Gitlab::Regex.oci_repository_path_regex_message} " \ + "It can only contain alphanumeric characters, periods, underscores, and dashes. " \ + "For example, 'destination_namespace' not 'destination/namespace'" + ) + end end end @@ -21,26 +33,24 @@ module API def validate_param!(attr_name, params) return if params[attr_name].blank? - unless params[attr_name] =~ Gitlab::Regex.bulk_import_destination_namespace_path_regex # rubocop: disable Style/GuardClause - raise Grape::Exceptions::Validation.new( - params: [@scope.full_name(attr_name)], - message: "cannot start with a dash or forward slash, or end with a period or forward slash. " \ - "It can only contain alphanumeric characters, periods, underscores, forward slashes " \ - "and dashes. E.g. 'destination_namespace' or 'destination/namespace'" - ) - end + return if params[attr_name] =~ Gitlab::Regex.bulk_import_destination_namespace_path_regex + + raise Grape::Exceptions::Validation.new( + params: [@scope.full_name(attr_name)], + message: Gitlab::Regex.bulk_import_destination_namespace_path_regex_message + ) end end class SourceFullPath < Grape::Validations::Base def validate_param!(attr_name, params) - unless params[attr_name] =~ Gitlab::Regex.bulk_import_source_full_path_regex # rubocop: disable Style/GuardClause - raise Grape::Exceptions::Validation.new( - params: [@scope.full_name(attr_name)], - message: "must be a relative path and not include protocol, sub-domain, or domain information. " \ - "E.g. 'source/full/path' not 'https://example.com/source/full/path'" \ - ) - end + return if params[attr_name] =~ Gitlab::Regex.bulk_import_source_full_path_regex + + raise Grape::Exceptions::Validation.new( + params: [@scope.full_name(attr_name)], + message: "must be a relative path and not include protocol, sub-domain, or domain information. " \ + "For example, 'source/full/path' not 'https://example.com/source/full/path'" \ + ) end end end |