mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +08:00
FIX: InlineUploads
raises an error when img tag is invalid.
This commit is contained in:
parent
d49c193289
commit
ff48fbdfda
|
@ -195,9 +195,9 @@ class InlineUploads
|
|||
def self.match_img(markdown, external_src: false)
|
||||
markdown.scan(/(<(?!img)[^<>]+\/?>)?(\n*)(([ ]*)<img ([^<>]+)>([ ]*))(\n*)/) do |match|
|
||||
node = Nokogiri::HTML::fragment(match[2].strip).children[0]
|
||||
src = node.attributes["src"].value
|
||||
src = node.attributes["src"]&.value
|
||||
|
||||
if matched_uploads(src).present? || external_src
|
||||
if src && (matched_uploads(src).present? || external_src)
|
||||
text = node.attributes["alt"]&.value
|
||||
width = node.attributes["width"]&.value
|
||||
height = node.attributes["height"]&.value
|
||||
|
|
|
@ -45,6 +45,20 @@ RSpec.describe InlineUploads do
|
|||
expect(InlineUploads.process(md)).to eq(md)
|
||||
end
|
||||
|
||||
it "should work with invalid img tags" do
|
||||
md = <<~MD
|
||||
<img src="#{upload.url}">
|
||||
|
||||
This is an invalid `<img ...>` tag
|
||||
MD
|
||||
|
||||
expect(InlineUploads.process(md)).to eq(<<~MD)
|
||||
![](#{upload.short_url})
|
||||
|
||||
This is an invalid `<img ...>` tag
|
||||
MD
|
||||
end
|
||||
|
||||
it "should not correct code blocks" do
|
||||
md = "`<a class=\"attachment\" href=\"#{upload2.url}\">In Code Block</a>`"
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user