diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb index 687d9a4..6bef743 100644 --- a/app/helpers/messages_helper.rb +++ b/app/helpers/messages_helper.rb @@ -118,13 +118,13 @@ module MessagesHelper # auto_link finds URLs and email addresses with regular expressions, which # can't tell an attribute value from text. Hand it one text node at a time, - # escaped, so a link can only land between tags. + # escaped as the serializer writes text, so a link can only land between tags. def auto_link_text(html) fragment = Nokogiri::HTML5.fragment(sanitize(html, tags: AUTO_LINK_ALLOWED_TAGS, attributes: AUTO_LINK_ALLOWED_ATTRIBUTES)) fragment.xpath(".//text()[not(ancestor::a)]").each do |node| if node.text.match?(LINKABLE_TEXT) - text = h(node.text) + text = node.to_html linked = auto_link(text, html: { target: "_blank" }) node.replace Nokogiri::HTML5.fragment(linked) unless linked == text end diff --git a/test/helpers/messages_helper_test.rb b/test/helpers/messages_helper_test.rb index 911317a..83902f5 100644 --- a/test/helpers/messages_helper_test.rb +++ b/test/helpers/messages_helper_test.rb @@ -46,6 +46,13 @@ class MessagesHelperTest < ActionView::TestCase assert_equal [ "https://example.com/a?b=1&c=2", "me@example.com" ], links.map(&:text) end + test "message_presentation links an email address with an apostrophe whole" do + message = Message.create! room: rooms(:pets), body: "