Parse comment html as fragments instead of docs (#7419)
This commit is contained in:
parent
1f74b95e34
commit
98365c878e
2 changed files with 8 additions and 1 deletions
|
|
@ -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?("<img") || anchor.attr("class")&.include?("ltag")
|
||||
anchor.content = strip_url(anchor.content) unless anchor.to_s.include?("<img")
|
||||
|
|
|
|||
|
|
@ -153,6 +153,13 @@ RSpec.describe Comment, type: :model do
|
|||
comment.validate!
|
||||
expect(comment.processed_html.include?(">1:52:30</a>")).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("<!DOCTYPE")
|
||||
expect(comment.processed_html).not_to include("<html><body>")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue