diff --git a/app/models/blip.rb b/app/models/blip.rb index 62bc2ac94..64e23a295 100644 --- a/app/models/blip.rb +++ b/app/models/blip.rb @@ -5,6 +5,7 @@ class Blip < ApplicationRecord simple_versioning belongs_to_creator belongs_to_updater optional: true + normalizes :body, with: ->(body) { body.gsub("\r\n", "\n") } validates :body, presence: true validates :body, length: { minimum: 5, maximum: Danbooru.config.blip_max_size } validate :validate_parent_exists, on: :create diff --git a/app/models/comment.rb b/app/models/comment.rb index 859aa119b..8e2a0b7ed 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -6,6 +6,7 @@ class Comment < ApplicationRecord simple_versioning belongs_to_creator belongs_to_updater + normalizes :body, with: ->(body) { body.gsub("\r\n", "\n") } validate :validate_post_exists, on: :create validate :validate_creator_is_not_limited, on: :create validate :post_not_comment_locked, on: :create diff --git a/app/models/dmail.rb b/app/models/dmail.rb index a4d7d6858..1d5ed6698 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class Dmail < ApplicationRecord + normalizes :body, with: ->(body) { body.gsub("\r\n", "\n") } validates :title, :body, presence: { on: :create } validates :title, length: { minimum: 1, maximum: 250 } validates :body, length: { minimum: 1, maximum: Danbooru.config.dmail_max_size } diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 45f650981..fcab44ea3 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -16,6 +16,7 @@ class ForumPost < ApplicationRecord before_validation :initialize_is_hidden, :on => :create after_create :update_topic_updated_at_on_create after_destroy :update_topic_updated_at_on_destroy + normalizes :body, with: ->(body) { body.gsub("\r\n", "\n") } validates :body, :creator_id, presence: true validates :body, length: { minimum: 1, maximum: Danbooru.config.forum_post_max_size } validate :validate_topic_is_unlocked diff --git a/app/models/note.rb b/app/models/note.rb index 2cf867288..79884049c 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -7,6 +7,7 @@ class Note < ApplicationRecord belongs_to :post belongs_to_creator has_many :versions, -> {order("note_versions.id ASC")}, :class_name => "NoteVersion", :dependent => :destroy + normalizes :body, with: ->(body) { body.gsub("\r\n", "\n") } validates :post_id, :creator_id, :x, :y, :width, :height, :body, presence: true validate :user_not_limited validate :post_must_exist diff --git a/app/models/pool.rb b/app/models/pool.rb index 0aa60bb24..7930268ba 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -7,6 +7,7 @@ class Pool < ApplicationRecord array_attribute :post_ids, parse: %r{(?:https://(?:e621|e926)\.net/posts/)?(\d+)}i, cast: :to_i belongs_to_creator + normalizes :description, with: ->(desc) { desc.gsub("\r\n", "\n") } validates :name, uniqueness: { case_sensitive: false, if: :name_changed? } validates :name, length: { minimum: 1, maximum: 250 } validates :description, length: { maximum: Danbooru.config.pool_descr_max_size } diff --git a/app/models/post.rb b/app/models/post.rb index 680a11af5..ad1954289 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -18,6 +18,7 @@ class Post < ApplicationRecord before_validation :fix_bg_color before_validation :blank_out_nonexistent_parents before_validation :remove_parent_loops + normalizes :description, with: ->(desc) { desc.gsub("\r\n", "\n") } validates :md5, uniqueness: { :on => :create, message: ->(obj, data) {"duplicate: #{Post.find_by_md5(obj.md5).id}"} } validates :rating, inclusion: { in: %w(s q e), message: "rating must be s, q, or e" } validates :bg_color, format: { with: /\A[A-Fa-f0-9]{6}\z/ }, allow_nil: true diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 81f550c77..3a4ab31ea 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -10,6 +10,7 @@ class Ticket < ApplicationRecord before_validation :initialize_fields, on: :create after_initialize :validate_type after_initialize :classify + normalizes :reason, with: ->(reason) { reason.gsub("\r\n", "\n") } validates :qtype, presence: true validates :reason, presence: true validates :reason, length: { minimum: 2, maximum: Danbooru.config.ticket_max_size } diff --git a/app/models/user.rb b/app/models/user.rb index 53a5f8b92..5c0956c23 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -65,6 +65,7 @@ class User < ApplicationRecord validates :email, length: { maximum: 100 } validate :validate_email_address_allowed, on: [:create, :update], if: ->(rec) { (rec.new_record? && rec.email.present?) || (rec.email.present? && rec.email_changed?) } + normalizes :profile_about, :profile_artinfo, with: ->(value) { value.gsub("\r\n", "\n") } validates :name, user_name: true, on: :create validates :default_image_size, inclusion: { :in => %w(large fit fitv original) } validates :per_page, inclusion: { :in => 1..320 } diff --git a/app/models/user_feedback.rb b/app/models/user_feedback.rb index d8a4ab158..d3361d98f 100644 --- a/app/models/user_feedback.rb +++ b/app/models/user_feedback.rb @@ -5,6 +5,7 @@ class UserFeedback < ApplicationRecord belongs_to :user belongs_to_creator belongs_to_updater + normalizes :body, with: ->(body) { body.gsub("\r\n", "\n") } validates :body, :category, presence: true validates :category, inclusion: { in: %w[positive negative neutral] } validates :body, length: { minimum: 1, maximum: Danbooru.config.user_feedback_max_size } diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 42969006f..a0ae4c1cd 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -7,6 +7,7 @@ class WikiPage < ApplicationRecord before_validation :normalize_other_names before_validation :normalize_parent after_save :create_version + normalizes :body, with: ->(body) { body.gsub("\r\n", "\n") } validates :title, uniqueness: { :case_sensitive => false } validates :title, presence: true validates :title, tag_name: true, if: :title_changed?