-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pasting: Dismiss pasted image if file:// schema detected #42785
Conversation
Fixes #42783 This isn't the fix that I would like, and I am not sure that it should be merged. IMO, the underlying issue is that Google Chrome (and Chromium derivatives) decides to attach to the clipboard data the fallback snapshot provided by Microsoft Word. Other browsers ignore that data, only passing attachments of type `text/plain`, `text/html`, and sometimes `text/rtf`.
Size Change: +37 B (0%) Total Size: 1.26 MB
ℹ️ View Unchanged
|
@@ -70,7 +70,16 @@ export function shouldDismissPastedFiles( files, html /*, plainText */ ) { | |||
// other elements found, like <figure>, but we assume that the user's | |||
// intention is to paste the actual image file. | |||
const IMAGE_TAG = /<\s*img\b/gi; | |||
return html.match( IMAGE_TAG )?.length !== 1; | |||
if ( html.match( IMAGE_TAG )?.length !== 1 ) return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this mean we should dismiss files? Should we check if the length is the same as the amount of files provided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see the files?.length === 1
check now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the two if-statements combined mean that we can only dismiss files when there is a mismatch between the number of files and the number of IMG tags in the HTML. The first if-statement just reduces the surface area of this helper, making it more conservative (e.g. there haven't been reports of unexpected file pastes when there is more than one file, so might as well only check with files.length == 1
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me. I guess we'll get reports if file dropping or pasting no longer works under some circumstances? It would be cool to collect various samples from different configurations and add them to the integration tests like we do for HTML paste.
Thanks for the vote of confidence! Yeah, let's keep a close eye on possible regressions, and if this comes back we should look into developing an integration suite. |
What?
Fixes #42783
This isn't the fix that I would like, and I am not sure that it should be merged.
IMO, the underlying issue is that Google Chrome (and Chromium derivatives, including Microsoft Edge) decides to attach to the clipboard data the fallback snapshot provided by Microsoft Word. Other browsers ignore that data, only passing attachments of type
text/plain
,text/html
, and sometimestext/rtf
.Why?
Quoting the bug report from the parent issue:
In short:
Gutenberg should ignore that attached snapshot.
How?
This PR extends the
shouldDismissPastedFiles
predicate to detect cases where the image tag found in the pasted HTML payload has a source with schemafile://
. For example,{ html: '<p>text</p><img src="file:///some/local/path">' }
. Notes:clipboardData.files
would be enough and we wouldn't have to guess based onclipboardData.getData( 'text/html' )
. However, I haven't spotted any (meta)data in there that we could use.Testing Instructions
See parent issue.
Caveat
I'm confident that this PR fixes that particular edge case, but it makes assumptions that I don't like, potentially creating new classes of false positives.
There's always the possibility of filing an issue / asking around in the Chromium project, to determine whether we could consider this a browser bug.