From 98365c878ef78c23d993cf316236166dab1dda0f Mon Sep 17 00:00:00 2001 From: Josh Puetz Date: Tue, 21 Apr 2020 15:01:44 -0500 Subject: [PATCH] Parse comment html as fragments instead of docs (#7419) --- app/models/comment.rb | 2 +- spec/models/comment_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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