From efd55141c91130569637ebceb304e0c191d601ee Mon Sep 17 00:00:00 2001 From: trichoplax Date: Fri, 31 Jul 2026 05:04:00 +0100 Subject: [PATCH 1/2] Normalize the body_markdown field of the Suggested Edit model --- app/models/suggested_edit.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/suggested_edit.rb b/app/models/suggested_edit.rb index 0c9751750..c89c50c94 100644 --- a/app/models/suggested_edit.rb +++ b/app/models/suggested_edit.rb @@ -16,6 +16,10 @@ class SuggestedEdit < ApplicationRecord has_one :post_type, through: :post has_one :category, through: :post + normalizes :body_markdown, with: lambda { |body_markdown| + body_markdown.encode(body_markdown.encoding, universal_newline: true) + } + after_save :clear_pending_cache, if: proc { saved_change_to_attribute?(:active) } scope :approved, -> { where(active: false, accepted: true) } From 9903624533f2bdbbdbf38c7e15be15b93875a629 Mon Sep 17 00:00:00 2001 From: trichoplax Date: Fri, 31 Jul 2026 05:22:12 +0100 Subject: [PATCH 2/2] Move body_markdown normalization into post_validations concern --- app/models/concerns/post_validations.rb | 4 ++++ app/models/post.rb | 4 ---- app/models/suggested_edit.rb | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/models/concerns/post_validations.rb b/app/models/concerns/post_validations.rb index e202e5fc9..9b8fa745a 100644 --- a/app/models/concerns/post_validations.rb +++ b/app/models/concerns/post_validations.rb @@ -3,6 +3,10 @@ module PostValidations extend ActiveSupport::Concern included do + normalizes :body_markdown, with: lambda { |body_markdown| + body_markdown.encode(body_markdown.encoding, universal_newline: true) + } + validate :tags_in_tag_set, if: -> { post_type.has_tags } validate :maximum_tags, if: -> { post_type.has_tags } validate :maximum_tag_length, if: -> { post_type.has_tags } diff --git a/app/models/post.rb b/app/models/post.rb index 60a4505d7..6b8f12b94 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -31,10 +31,6 @@ class Post < ApplicationRecord serialize :tags_cache, coder: YAML, type: Array - normalizes :body_markdown, with: lambda { |body_markdown| - body_markdown.encode(body_markdown.encoding, universal_newline: true) - } - validates :body, presence: true, length: { maximum: 65_535 } validates :body_markdown, presence: true, length: { maximum: 30_000 } validates :doc_slug, uniqueness: { scope: [:community_id], case_sensitive: false }, if: -> { doc_slug.present? } diff --git a/app/models/suggested_edit.rb b/app/models/suggested_edit.rb index c89c50c94..0c9751750 100644 --- a/app/models/suggested_edit.rb +++ b/app/models/suggested_edit.rb @@ -16,10 +16,6 @@ class SuggestedEdit < ApplicationRecord has_one :post_type, through: :post has_one :category, through: :post - normalizes :body_markdown, with: lambda { |body_markdown| - body_markdown.encode(body_markdown.encoding, universal_newline: true) - } - after_save :clear_pending_cache, if: proc { saved_change_to_attribute?(:active) } scope :approved, -> { where(active: false, accepted: true) }