diff --git a/app/models/comment.rb b/app/models/comment.rb index c3c460815..def361547 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -12,6 +12,8 @@ class Comment < ApplicationRecord TITLE_DELETED = "[deleted]".freeze TITLE_HIDDEN = "[hidden by post author]".freeze + URI_REGEXP = %r{(?https?://)?(?.+?)(?:\d+)?$}.freeze + # The date that we began limiting the number of user mentions in a comment. MAX_USER_MENTION_LIVE_AT = Time.utc(2021, 3, 12).freeze @@ -202,9 +204,12 @@ class Comment < ApplicationRecord def shorten_urls! doc = Nokogiri::HTML.fragment(processed_html) doc.css("a").each do |anchor| - unless anchor.to_s.include?("")).to be(true) + expect(comment.processed_html.include?("...")).to be(true) expect(comment.processed_html.size < 450).to be(true) + + comment.body_markdown = "Hello [**#{long_url}**](#{long_url})" + comment.validate! + expect(comment.processed_html.include?("...")).to be(true) + + comment.body_markdown = "Hello ![Alt-text](#{long_url})" + comment.validate! + expect(comment.processed_html.include?("