mirror of
https://github.com/discourse/discourse.git
synced 2025-03-14 10:33:43 +00:00
FIX: copy image from cooked to rich editor (#31804)
When copying images from cooked, we have a `data-base62-sha1` attribute instead of a `data-orig-src` that we were expecting. This PR fixes it and adds a system test.
This commit is contained in:
@ -39,7 +39,11 @@ const extension = {
|
||||
alt: dom.getAttribute("alt"),
|
||||
width: dom.getAttribute("width"),
|
||||
height: dom.getAttribute("height"),
|
||||
originalSrc: dom.dataset.origSrc,
|
||||
originalSrc:
|
||||
dom.dataset.origSrc ??
|
||||
(dom.dataset.base62Sha1
|
||||
? `upload://${dom.dataset.base62Sha1}`
|
||||
: undefined),
|
||||
extras: dom.hasAttribute("data-thumbnail")
|
||||
? "thumbnail"
|
||||
: undefined,
|
||||
|
@ -433,6 +433,21 @@ describe "Composer - ProseMirror editor", type: :system do
|
||||
expect(rich).to have_css("pre code", wait: 1)
|
||||
expect(rich).to have_css("select.code-language-select", wait: 1)
|
||||
end
|
||||
|
||||
it "parses images copied from cooked with base62-sha1" do
|
||||
cdp.allow_clipboard
|
||||
open_composer_and_toggle_rich_editor
|
||||
|
||||
cdp.write_clipboard(
|
||||
'<img src="image.png" alt="alt text" data-base62-sha1="1234567890">',
|
||||
html: true,
|
||||
)
|
||||
page.send_keys([PLATFORM_KEY_MODIFIER, "v"])
|
||||
|
||||
expect(page).to have_css(
|
||||
"img[src$='image.png'][alt='alt text'][data-orig-src='upload://1234567890']",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "trailing paragraph" do
|
||||
|
@ -30,11 +30,23 @@ module PageObjects
|
||||
page.evaluate_async_script("navigator.clipboard.readText().then(arguments[0])")
|
||||
end
|
||||
|
||||
def write_clipboard(text)
|
||||
page.evaluate_async_script(
|
||||
"navigator.clipboard.writeText(arguments[0]).then(arguments[1])",
|
||||
text,
|
||||
)
|
||||
def write_clipboard(content, html: false)
|
||||
if html
|
||||
page.evaluate_async_script(
|
||||
"navigator.clipboard.write([
|
||||
new ClipboardItem({
|
||||
'text/html': new Blob([arguments[0]], { type: 'text/html' }),
|
||||
'text/plain': new Blob([arguments[0]], { type: 'text/plain' })
|
||||
})
|
||||
]).then(arguments[1])",
|
||||
content,
|
||||
)
|
||||
else
|
||||
page.evaluate_async_script(
|
||||
"navigator.clipboard.writeText(arguments[0]).then(arguments[1])",
|
||||
content,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def clipboard_has_text?(text, chomp: false, strict: true)
|
||||
|
Reference in New Issue
Block a user