diff --git a/app/models/comment.rb b/app/models/comment.rb index f7a807463..f8331ad91 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -164,7 +164,7 @@ class Comment < ApplicationRecord end def shorten_urls! - doc = Nokogiri::HTML.parse(processed_html) + doc = Nokogiri::HTML.fragment(processed_html) doc.css("a").each do |anchor| unless anchor.to_s.include?("1:52:30")).to eq(false) end + + it "does not add DOCTYPE and html body to processed html" do + comment.body_markdown = "Hello https://longurl.com/#{'x' * 100}?#{'y' * 100}" + comment.validate! + expect(comment.processed_html).not_to include("") + end end end