From 8e59b3ef4781210efeb7f6540ace5a3bdabb2188 Mon Sep 17 00:00:00 2001 From: albertlast Date: Fri, 4 Sep 2026 23:00:27 +0200 Subject: [PATCH] Widens the report comment column to fit an entity encoded report Reporting a post stores the comment with HTML entities in place of the characters that need them, so a double quote costs six characters, an ampersand five and an angle bracket four. The form allows 254 characters and the column held 255, which leaves no room at all for that: a report that quotes the post it is about, or pastes a link with a query string, overflows the column and the insert fails with "Data too long for column 'comment'" on MySQL, or "value too long for type character varying(255)" on PostgreSQL. The report row is written before the comment is, so the failure also leaves a report behind with no comment on it and no notification sent. Makes the column a text column, which holds the encoded form of anything the form's own length check lets through. Co-Authored-By: Claude Opus 5 Signed-off-by: albertlast --- .../Db/Schema/v3_0/LogReportedComments.php | 4 +- .../Migration/v3_0/ReportCommentLength.php | 71 +++++++++++++++++++ Sources/Maintenance/Tools/Upgrade.php | 1 + 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 Sources/Maintenance/Migration/v3_0/ReportCommentLength.php diff --git a/Sources/Db/Schema/v3_0/LogReportedComments.php b/Sources/Db/Schema/v3_0/LogReportedComments.php index f78886777a7..0aede744f09 100644 --- a/Sources/Db/Schema/v3_0/LogReportedComments.php +++ b/Sources/Db/Schema/v3_0/LogReportedComments.php @@ -69,10 +69,8 @@ public function __construct() ), 'comment' => new Column( name: 'comment', - type: 'varchar', - size: 255, + type: 'text', not_null: true, - default: '', ), 'time_sent' => new Column( name: 'time_sent', diff --git a/Sources/Maintenance/Migration/v3_0/ReportCommentLength.php b/Sources/Maintenance/Migration/v3_0/ReportCommentLength.php new file mode 100644 index 00000000000..6602f413366 --- /dev/null +++ b/Sources/Maintenance/Migration/v3_0/ReportCommentLength.php @@ -0,0 +1,71 @@ +getCurrentStructure(); + + foreach ($existing_structure['columns'] as $column) { + if ($column['name'] === 'comment') { + return $column['type'] !== $table->columns['comment']->type; + } + } + + return false; + } + + /** + * + */ + public function execute(): bool + { + $table = new Schema\v3_0\LogReportedComments(); + + foreach ($table->columns as $column) { + if ($column->name === 'comment') { + // A text column takes no default, so the varchar one has to go. + $column->drop_default = true; + + $table->alterColumn($column); + } + } + + return true; + } +} diff --git a/Sources/Maintenance/Tools/Upgrade.php b/Sources/Maintenance/Tools/Upgrade.php index bda39f8ca07..7a0b80ea187 100644 --- a/Sources/Maintenance/Tools/Upgrade.php +++ b/Sources/Maintenance/Tools/Upgrade.php @@ -182,6 +182,7 @@ class Upgrade extends ToolsBase implements ToolsInterface Migration\v3_0\PermissionChanges::class, Migration\v3_0\BoardPostsCount::class, Migration\v3_0\ValidationCodeLength::class, + Migration\v3_0\ReportCommentLength::class, ], ];