diff --git a/app/models/namespace.rb b/app/models/namespace.rb index cd58710825d45a2c69c3ae72bea046ec36bb9683..b19b72906e7b0981b2326fec6b4f71dc923b66ae 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -23,12 +23,12 @@ class Namespace < ActiveRecord::Base validates :name, presence: true, uniqueness: true, length: { within: 0..255 }, format: { with: Gitlab::Regex.name_regex, - message: "only letters, digits, spaces & '_' '-' '.' allowed." } + message: Gitlab::Regex.name_regex_message } validates :description, length: { within: 0..255 } validates :path, uniqueness: { case_sensitive: false }, presence: true, length: { within: 1..255 }, exclusion: { in: Gitlab::Blacklist.path }, format: { with: Gitlab::Regex.path_regex, - message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } + message: Gitlab::Regex.path_regex_message } delegate :name, to: :owner, allow_nil: true, prefix: true diff --git a/app/models/project.rb b/app/models/project.rb index f20581428dca38864304b9e8d1aa9b921d590778..96e9b515cb5905875253b635e245aa630e65cef4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -90,11 +90,11 @@ class Project < ActiveRecord::Base validates :description, length: { maximum: 2000 }, allow_blank: true validates :name, presence: true, length: { within: 0..255 }, format: { with: Gitlab::Regex.project_name_regex, - message: "only letters, digits, spaces & '_' '-' '.' allowed. Letter or digit should be first" } + message: Gitlab::Regex.project_regex_message } validates :path, presence: true, length: { within: 0..255 }, exclusion: { in: Gitlab::Blacklist.path }, format: { with: Gitlab::Regex.path_regex, - message: "only letters, digits & '_' '-' '.' allowed. Letter or digit should be first" } + message: Gitlab::Regex.path_regex_message } validates :issues_enabled, :merge_requests_enabled, :wiki_enabled, inclusion: { in: [true, false] } validates :visibility_level, diff --git a/app/models/user.rb b/app/models/user.rb index 5fca392d3501543bd2f0ac483cb9a2f2c147b1be..6d7350881df86125636e49b074f399f76dee300f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -113,7 +113,7 @@ class User < ActiveRecord::Base validates :username, presence: true, uniqueness: { case_sensitive: false }, exclusion: { in: Gitlab::Blacklist.path }, format: { with: Gitlab::Regex.username_regex, - message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } + message: Gitlab::Regex.username_regex_message } validates :notification_level, inclusion: { in: Notification.notification_levels }, presence: true validate :namespace_uniq, if: ->(user) { user.username_changed? } diff --git a/app/services/files/create_service.rb b/app/services/files/create_service.rb index 1998fb79e7d233b25adf4ff1c1481c1391cb32cc..82e4d7b684f11dd445566e61107fe182e267077f 100644 --- a/app/services/files/create_service.rb +++ b/app/services/files/create_service.rb @@ -21,7 +21,10 @@ module Files file_path = path unless file_name =~ Gitlab::Regex.path_regex - return error("Your changes could not be committed, because file name contains not allowed characters") + return error( + 'Your changes could not be committed, because the file name ' + + Gitlab::Regex.path_regex_message + ) end blob = repository.blob_at_branch(ref, file_path) diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index e932b64f4f0ce1ac5a4e038e5360cc2009a98a92..153613760fe9c5a9b3d0e379576739185221f77c 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -6,18 +6,35 @@ module Gitlab default_regex end + def username_regex_message + default_regex_message + end + def project_name_regex /\A[a-zA-Z0-9_][a-zA-Z0-9_\-\. ]*\z/ end + def project_regex_message + "can contain only letters, digits, '_', '-' and '.' and space. " \ + "It must start with letter, digit or '_'." + end + def name_regex /\A[a-zA-Z0-9_\-\. ]*\z/ end + def name_regex_message + "can contain only letters, digits, '_', '-' and '.' and space." + end + def path_regex default_regex end + def path_regex_message + default_regex_message + end + def archive_formats_regex #|zip|tar| tar.gz | tar.bz2 | /(zip|tar|tar\.gz|tgz|gz|tar\.bz2|tbz|tbz2|tb2|bz2)/ @@ -48,6 +65,12 @@ module Gitlab protected + def default_regex_message + "can contain only letters, digits, '_', '-' and '.'. " \ + "It must start with letter, digit or '_', optionally preceeded by '.'. " \ + "It must not end in '.git'." + end + def default_regex /\A[.?]?[a-zA-Z0-9_][a-zA-Z0-9_\-\.]*(?<!\.git)\z/ end