From 00300b118d54605e6bb3f1ffcb685b1944100bb2 Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Mon, 31 May 2021 14:59:40 +0400 Subject: [PATCH] FIX: errors that're triggering by too long excerpts (#13056) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The excerpt field in the database is constrained to 1000 chars in length. To support this constraint we added a restriction that the topic_excerpt_maxlength setting must be between 0 and 999. Unfortunately, sometimes it doesn’t work because: - topic_excerpt_maxlength restricts the length of a visible to user excerpt. But we HTML-escape text before saving. If an excerpt contains & it’ll be &. One character for the user but 5 characters to save to the database. So if topic_excerpt_maxlength is set to 999 it’s not so hard to have an excerpt of for example 1003 characters in length and run into this issue. - It’s possible to define a custom excerpt for a topic. Such excerpts bypass check for a length. So if the user defines a too long custom excerpt he will run into this issue. Removing the constraint on the database level solves the problem. But we still need the constraint for topic_excerpt_maxlength on the setting page, because too long excerpts would make UI wonky. --- ...5608_remove_length_constrain_from_topic_excerpt.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 db/post_migrate/20210513125608_remove_length_constrain_from_topic_excerpt.rb diff --git a/db/post_migrate/20210513125608_remove_length_constrain_from_topic_excerpt.rb b/db/post_migrate/20210513125608_remove_length_constrain_from_topic_excerpt.rb new file mode 100644 index 00000000000..3989692b545 --- /dev/null +++ b/db/post_migrate/20210513125608_remove_length_constrain_from_topic_excerpt.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class RemoveLengthConstrainFromTopicExcerpt < ActiveRecord::Migration[6.1] + def up + change_column :topics, :excerpt, :string, null: true + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end