Skip to content

Commit

Permalink
Don't ignore legitimate files when pasting mixed content (#38459)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcsf authored Feb 3, 2022
1 parent 03a5fc7 commit ed96b72
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,22 @@ export function usePasteHandler( props ) {
return;
}

// Only process file if no HTML is present.
// Note: a pasted file may have the URL as plain text.
if ( files && files.length && ! html ) {
// Process any attached files, unless we detect Microsoft Office as
// the source.
//
// When content is copied from Microsoft Office, an image of the
// content is rendered and attached to the clipboard along with the
// plain-text and HTML content. This artifact is a distraction from
// the relevant clipboard data, so we ignore it.
//
// Props https://github.com/pubpub/pubpub/commit/2f933277a15a263a1ab4bbd36b96d3a106544aec
if (
files &&
files.length &&
! html?.includes(
'xmlns:o="urn:schemas-microsoft-com:office:office'
)
) {
const content = pasteHandler( {
HTML: filePasteHandler( files ),
mode: 'BLOCKS',
Expand Down

0 comments on commit ed96b72

Please sign in to comment.