From 3ca8b63643b9cfa6ef964673aa4fff2cbeee78a3 Mon Sep 17 00:00:00 2001
From: Harry Wood
Date: Fri, 6 May 2022 12:41:04 +0100
Subject: [PATCH] Put issue comments through kramdown formatter
On issue comments (which only admins can create or see), put the `body` text through kramdown formatting.
---
app/models/issue_comment.rb | 4 ++++
app/views/issues/_comments.html.erb | 2 +-
test/models/issue_comment_test.rb | 5 +++++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/app/models/issue_comment.rb b/app/models/issue_comment.rb
index 07647d679..8d150a02f 100644
--- a/app/models/issue_comment.rb
+++ b/app/models/issue_comment.rb
@@ -25,4 +25,8 @@ class IssueComment < ApplicationRecord
belongs_to :user
validates :body, :presence => true, :characters => true
+
+ def body
+ RichText.new("markdown", self[:body])
+ end
end
diff --git a/app/views/issues/_comments.html.erb b/app/views/issues/_comments.html.erb
index e55bf4257..390977b65 100644
--- a/app/views/issues/_comments.html.erb
+++ b/app/views/issues/_comments.html.erb
@@ -9,7 +9,7 @@
<%= t ".comment_from_html", :user_link => link_to(comment.user.display_name, user_path(comment.user)),
:comment_created_at => l(comment.created_at.to_datetime, :format => :friendly) %>
- <%= comment.body %>
+ <%= comment.body.to_html %>
diff --git a/test/models/issue_comment_test.rb b/test/models/issue_comment_test.rb
index 27fa9d66d..7a1191ead 100644
--- a/test/models/issue_comment_test.rb
+++ b/test/models/issue_comment_test.rb
@@ -6,4 +6,9 @@ class IssueCommentTest < ActiveSupport::TestCase
assert_not comment.valid?
assert_not_nil comment.errors[:body]
end
+
+ test "body" do
+ comment = create(:issue_comment)
+ assert_instance_of(RichText::Markdown, comment.body)
+ end
end
--
2.39.5