mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:50:00 +08:00
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:
parent
e9f7262813
commit
9a6e4b1fa1
|
@ -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],
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user