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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-13 15:08:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-13 15:08:49 +0300
commit1308dc5eb484ab0f8064989fc551ebdb4b1a7976 (patch)
tree614a93d9bf8df34ecfc25c02648329987fb21dde /app/models/wiki_page.rb
parentf0707f413ce49b5712fca236b950acbec029be1e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/wiki_page.rb')
-rw-r--r--app/models/wiki_page.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index c6867e48cbf..26beb77a025 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -5,6 +5,9 @@ class WikiPage
PageChangedError = Class.new(StandardError)
PageRenameError = Class.new(StandardError)
+ MAX_TITLE_BYTES = 245
+ MAX_DIRECTORY_BYTES = 255
+
include ActiveModel::Validations
include ActiveModel::Conversion
include StaticModel
@@ -51,6 +54,7 @@ class WikiPage
validates :title, presence: true
validates :content, presence: true
+ validate :validate_path_limits, if: :title_changed?
# The GitLab ProjectWiki instance.
attr_reader :wiki
@@ -262,7 +266,7 @@ class WikiPage
end
def title_changed?
- title.present? && self.class.unhyphenize(@page.url_path) != title
+ title.present? && (@page.nil? || self.class.unhyphenize(@page.url_path) != title)
end
# Updates the current @attributes hash by merging a hash of params
@@ -324,4 +328,16 @@ class WikiPage
set_attributes
@persisted = errors.blank?
end
+
+ def validate_path_limits
+ *dirnames, title = @attributes[:title].split('/')
+
+ if title.bytesize > MAX_TITLE_BYTES
+ errors.add(:title, _("exceeds the limit of %{bytes} bytes for page titles") % { bytes: MAX_TITLE_BYTES })
+ end
+
+ if dirnames.any? { |d| d.bytesize > MAX_DIRECTORY_BYTES }
+ errors.add(:title, _("exceeds the limit of %{bytes} bytes for directory names") % { bytes: MAX_DIRECTORY_BYTES })
+ end
+ end
end