FIX: Make InlineUploads handle more URL formats (#9467)

It previously failed to match URLs with characters other than `[a-zA-z0-9\.\/:-]`. This meant that `PullHotlinkedImages` would sometimes download an external image and then never use it in any posts.
This commit is contained in:
Jarek Radosz 2020-04-21 03:47:48 +02:00 committed by GitHub
parent e9f7262813
commit 9a6e4b1fa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -148,7 +148,7 @@ class InlineUploads
end
def self.match_md_inline_img(markdown, external_src: false)
markdown.scan(/(!?\[([^\[\]]*)\]\(([a-zA-z0-9\.\/:-]+)([ ]*['"]{1}[^\)]*['"]{1}[ ]*)?\))/) do |match|
markdown.scan(/(!?\[([^\[\]]*)\]\(([^\s\)]+)([ ]*['"]{1}[^\)]*['"]{1}[ ]*)?\))/) do |match|
if (matched_uploads(match[2]).present? || external_src) && block_given?
yield(
match[0],

View File

@ -712,4 +712,17 @@ RSpec.describe InlineUploads do
end
end
end
describe ".match_md_inline_img" do
it "matches URLs with various characters" do
md = <<~MD
![test](https://some-site.com/a_test?q=1&b=hello%20there)
MD
url = nil
InlineUploads.match_md_inline_img(md, external_src: true) { |_match, src| url = src }
expect(url).to eq("https://some-site.com/a_test?q=1&b=hello%20there")
end
end
end