FIX: Skip upload if HTML cannot be parsed (#12971)

This commit is contained in:
Bianca Nenciu
2021-05-14 16:52:40 +03:00
committed by GitHub
parent 3a1b05f219
commit c0679022e7
2 changed files with 6 additions and 1 deletions

View File

@@ -200,7 +200,7 @@ class InlineUploads
def self.match_img(markdown, external_src: false, uploads: nil)
markdown.scan(/(<(?!img)[^<>]+\/?>)?(\s*)(<img [^>\n]+>)/i) do |match|
node = Nokogiri::HTML5::fragment(match[2].strip).children[0]
src = node.attributes["src"]&.value
src = node&.attributes&.[]("src")&.value
if src && (matched_uploads(src).present? || external_src)
upload = uploads&.[](src)

View File

@@ -54,6 +54,11 @@ RSpec.describe InlineUploads do
MD
end
it "should work with invalid img tags" do
md = '<img data-id="<>">'
expect(InlineUploads.process(md)).to eq(md)
end
it "should not correct code blocks" do
md = "`<a class=\"attachment\" href=\"#{upload2.url}\">In Code Block</a>`"