From 2627530d48cde21f7873ad8d6a9dcd97ea66964a Mon Sep 17 00:00:00 2001 From: saint Date: Tue, 2 Jul 2024 13:50:36 +1000 Subject: [PATCH] v0.25.1 Another post content corner case handling for Discourse validation to pass --- gossamer_forums.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gossamer_forums.rb b/gossamer_forums.rb index 00dcf78..cadc7e1 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -1,5 +1,5 @@ # gossamer threads migration-import code -# v0.25 +# v0.25.1 require 'mysql2' require 'open-uri' @@ -781,6 +781,16 @@ class GossamerForumsImporter < ImportScripts::Base # Ensure the raw post string contents itself is acceptable to Discourse sanitized_message = message&.tr("\0", '') || "" + # Ensure minimum length + if sanitized_message.strip.empty? || sanitized_message.length < 3 + sanitized_message = "Empty post contents." + end + + # Ensure sentence structure + unless sanitized_message.match?(/[.!?]\s|[.!?]$/) + sanitized_message += "." + end + # Remove the [signature] as we don't support this in Discourse # sanitized_message.sub!(/\n?\[signature\]\n?\z/, '') sanitized_message.gsub(/\n?\[signature\]\n?/, '')