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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/projects/topic.rb')
-rw-r--r--app/models/projects/topic.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/models/projects/topic.rb b/app/models/projects/topic.rb
index 3155eede2bd..ed1795b43e0 100644
--- a/app/models/projects/topic.rb
+++ b/app/models/projects/topic.rb
@@ -9,6 +9,7 @@ module Projects
validates :name, presence: true, length: { maximum: 255 }
validates :name, uniqueness: { case_sensitive: false }, if: :name_changed?
+ validate :validate_name_format, if: :name_changed?
validates :title, presence: true, length: { maximum: 255 }, on: :create
validates :description, length: { maximum: 1024 }
@@ -62,6 +63,18 @@ module Projects
where(id: topics_to_decrement).where('non_private_projects_count > 0').update_counters(non_private_projects_count: -1) unless topics_to_decrement.empty?
end
end
+
+ private
+
+ def validate_name_format
+ return if name.blank?
+
+ # /\R/ - A linebreak: \n, \v, \f, \r \u0085 (NEXT LINE),
+ # \u2028 (LINE SEPARATOR), \u2029 (PARAGRAPH SEPARATOR) or \r\n.
+ return unless name =~ /\R/
+
+ errors.add(:name, 'has characters that are not allowed')
+ end
end
end