FIX: `InlineUploads` does not correct urls with uppercase extension.
This commit is contained in:
parent
fa2a5f6f56
commit
93c552afda
|
@ -6,7 +6,7 @@ class InlineUploads
|
|||
PLACEHOLDER = "__replace__"
|
||||
PATH_PLACEHOLDER = "__replace_path__"
|
||||
|
||||
UPLOAD_REGEXP_PATTERN = "/original/(\\dX/(?:[a-f0-9]/)*[a-f0-9]{40}[a-z0-9.]*)"
|
||||
UPLOAD_REGEXP_PATTERN = "/original/(\\dX/(?:[a-f0-9]/)*[a-f0-9]{40}[a-zA-Z0-9.]*)"
|
||||
private_constant :UPLOAD_REGEXP_PATTERN
|
||||
|
||||
def self.process(markdown, on_missing: nil)
|
||||
|
@ -232,9 +232,9 @@ class InlineUploads
|
|||
matches = []
|
||||
|
||||
regexps = [
|
||||
/(upload:\/\/([a-zA-Z0-9]+)[a-z0-9\.]*)/,
|
||||
/(\/uploads\/short-url\/([a-zA-Z0-9]+)[a-z0-9\.]*)/,
|
||||
/(#{Discourse.base_url}\/uploads\/short-url\/([a-zA-Z0-9]+)[a-z0-9\.]*)/,
|
||||
/(upload:\/\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
|
||||
/(\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
|
||||
/(#{Discourse.base_url}\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
|
||||
]
|
||||
|
||||
db = RailsMultisite::ConnectionManagement.current_db
|
||||
|
|
|
@ -211,6 +211,16 @@ RSpec.describe InlineUploads do
|
|||
MD
|
||||
end
|
||||
|
||||
it "should correct img tags with uppercase upload extension" do
|
||||
md = <<~MD
|
||||
test<img src="#{upload.url.sub(".png", ".PNG")}">
|
||||
MD
|
||||
|
||||
expect(InlineUploads.process(md)).to eq(<<~MD)
|
||||
test![](#{upload.short_url})
|
||||
MD
|
||||
end
|
||||
|
||||
it "should correct image URLs to the short version" do
|
||||
md = <<~MD
|
||||
![image|690x290](#{upload.short_url})
|
||||
|
@ -503,12 +513,14 @@ RSpec.describe InlineUploads do
|
|||
md = <<~MD
|
||||
#{upload.url}
|
||||
<img src="#{upload.url}" alt="some image">
|
||||
test<img src="#{upload2.url}" alt="some image">test
|
||||
<img src="#{URI.join(SiteSetting.s3_cdn_url, URI.parse(upload2.url).path).to_s}" alt="some image">
|
||||
MD
|
||||
|
||||
expect(InlineUploads.process(md)).to eq(<<~MD)
|
||||
![](#{upload.short_url})
|
||||
![some image](#{upload.short_url})
|
||||
test![some image](#{upload2.short_url})test
|
||||
![some image](#{upload2.short_url})
|
||||
MD
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue