FIX: errors that’re triggering by too long excerpts (#13056)
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.
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 0000000..3989692 --- /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
GitHub sha: 00300b11