-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Don't ignore legitimate files when pasting mixed content #38459
Conversation
Gutenberg's paste handler generally processes any files present in the clipboard data of a paste event. However, an exception was introduced in 2018 in #4882 to deal with the fact that paste objects from Microsoft Word and other Office software contain a rendered image of the copied content. Users expected the actual content to be pasted, not an image thereof. Thus, the exception consisted of ignoring any files if the clipboard also contained HTML data, favouring the latter. This exception is now leading to false positives. In certain platforms (e.g. Google Photos using Google Chrome), when users copy an image, the resulting clipboard includes fallback HTML data. With the present fix, pasted files are only ignored if the concurrent HTML data matches a distinct string signature from Microsoft Office.
Size Change: +39 B (0%) Total Size: 1.14 MB
ℹ️ View Unchanged
|
Testing in MS Word for Mac v16.57 and it appears to work great. I copied and pasted some formatted text into Gutenberg on this branch and it works exactly as it does on |
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.
This works correctly for me:
✅ I use "Copy Image" from a single image in Google Photos and paste it into the editor. The image appears as an image block, and the image is uploaded to my media library.
✅ I copy text from MS Word on the Mac, paste it into the editor. The text is pasted into the editor in a paragraph block like any other text.
Thank you for the quick reviews and merge! |
! html?.includes( | ||
'xmlns:o="urn:schemas-microsoft-com:office:office' | ||
) | ||
) { |
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.
There's another instance in packages/block-editor/src/components/rich-text/index.native.js that maybe needs to be adjusted. Maybe we need this code to be more reusable?
Could we add an integration test with the HTML source? |
Yeah, tests and the |
Follows up on #38459, applying the same fix to the RNMobile's RichTextWrapper.
@ellatrix: do we have precedents of integration tests simulating a file upload? The change in this PR only applies when we have files to work with in the clipboard alongside some HTML payload. |
Continues from #38459, fixing the issues it introduced.
Continues from #38459, fixing the issues it introduced.
The problem
Expected: The image is automatically uploaded to the site and appears in the form of an Image block
Observed: An image block appears but the image remains a external resource
To make matters worse, the option to manually upload the image is absent from this new image block.
Causes
There are two causes at play, one of which we have little control over:
On pasting
Gutenberg's paste handler generally processes any files present in the clipboard data of a paste event.
However, an exception was introduced in 2018 in #4882 to deal with the fact that paste objects from Microsoft Word and other Office software contain a rendered image of the copied content. Users expected the actual content to be pasted, not an image thereof. Thus, the workaround was to ignore any files if the clipboard also contained HTML data, favouring the latter.
This workaround is now leading to false positives. In certain platforms (e.g. Google Photos using Google Chrome), when users copy an image, the resulting clipboard includes fallback HTML data.
With the present fix, pasted files are only ignored if the concurrent HTML data matches a distinct string signature from Microsoft Office. Props pubpub/pubpub@2f93327 for the solution.
Testing Instructions
Types of changes
Bug fix
Checklist:
*.native.js
files for terms that need renaming or removal).