Skip to content

Commit

Permalink
FIX: InlineUploads raises an error when img tag is invalid.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgxworld committed Jun 12, 2019
1 parent d49c193 commit ff48fbd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/services/inline_uploads.rb
Expand Up @@ -195,9 +195,9 @@ def self.match_anchor(markdown, external_href: false)
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
Expand Down
14 changes: 14 additions & 0 deletions spec/services/inline_uploads_spec.rb
Expand Up @@ -45,6 +45,20 @@
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>`"

Expand Down

0 comments on commit ff48fbd

Please sign in to comment.