mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Support [description|attachment](upload://<short-sha>) in MD. (#7603)
This commit is contained in:
committed by
Penar Musaraj
parent
42818b810e
commit
b1d3c678ca
@@ -303,21 +303,12 @@ describe FileStore::S3Store do
|
||||
end
|
||||
|
||||
describe ".path_for" do
|
||||
|
||||
def assert_path(path, expected)
|
||||
upload = Upload.new(url: path)
|
||||
|
||||
path = store.path_for(upload)
|
||||
expected = FileStore::LocalStore.new.path_for(upload) if expected
|
||||
|
||||
expect(path).to eq(expected)
|
||||
end
|
||||
|
||||
it "correctly falls back to local" do
|
||||
assert_path("/hello", "/hello")
|
||||
assert_path("//hello", nil)
|
||||
assert_path("http://hello", nil)
|
||||
assert_path("https://hello", nil)
|
||||
local_upload = Fabricate(:upload)
|
||||
s3_upload = Fabricate(:upload_s3)
|
||||
|
||||
expect(Discourse.store.path_for(local_upload)).to eq(local_upload.url)
|
||||
expect(Discourse.store.path_for(s3_upload)).to eq(s3_upload.url)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1260,9 +1260,11 @@ HTML
|
||||
|
||||
end
|
||||
|
||||
describe "image decoding" do
|
||||
describe "upload decoding" do
|
||||
|
||||
it "can decode upload:// for default setup" do
|
||||
set_cdn_url('https://cdn.com')
|
||||
|
||||
upload = Fabricate(:upload)
|
||||
|
||||
raw = <<~RAW
|
||||
@@ -1274,6 +1276,12 @@ HTML
|
||||
- 
|
||||
|
||||
})
|
||||
|
||||
[some attachment](#{upload.short_url})
|
||||
|
||||
[some attachment|attachment](#{upload.short_url})
|
||||
|
||||
[some attachment|random](#{upload.short_url})
|
||||
RAW
|
||||
|
||||
cooked = <<~HTML
|
||||
@@ -1290,6 +1298,9 @@ HTML
|
||||
</li>
|
||||
</ul>
|
||||
<p><img src="#{upload.url}" alt="upload"></p>
|
||||
<p><a href="#{upload.short_path}">some attachment</a></p>
|
||||
<p><a class="attachment" href="#{upload.short_path}">some attachment</a></p>
|
||||
<p><a href="#{upload.short_path}">some attachment|random</a></p>
|
||||
HTML
|
||||
|
||||
expect(PrettyText.cook(raw)).to eq(cooked.strip)
|
||||
@@ -1297,10 +1308,15 @@ HTML
|
||||
|
||||
it "can place a blank image if we can not find the upload" do
|
||||
|
||||
raw = ""
|
||||
raw = <<~MD
|
||||

|
||||
|
||||
[some attachment|attachment](upload://abcdefg.png)
|
||||
MD
|
||||
|
||||
cooked = <<~HTML
|
||||
<p><img src="/images/transparent.png" alt="upload" data-orig-src="upload://abcABC.png"></p>
|
||||
<p><img src="/images/transparent.png" alt="upload" data-orig-src="upload://abcABC.png"></p>
|
||||
<p><a href="/404" data-orig-href="upload://abcdefg.png">some attachment|attachment</a></p>
|
||||
HTML
|
||||
|
||||
expect(PrettyText.cook(raw)).to eq(cooked.strip)
|
||||
|
||||
Reference in New Issue
Block a user