Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export function usePasteHandler( props ) {
// Remove Windows-specific metadata appended within copied HTML text.
html = removeWindowsFragments( html );

// Strip meta tag.
html = removeCharsetMetaTag( html );

event.preventDefault();

// Allows us to ask for this information when we get a report.
Expand Down Expand Up @@ -257,3 +260,22 @@ function removeWindowsFragments( html ) {

return html.replace( startReg, '' ).replace( endReg, '' );
}

/**
* Removes the charset meta tag inserted by Chromium.
* See:
* - https://github.com/WordPress/gutenberg/issues/33585
* - https://bugs.chromium.org/p/chromium/issues/detail?id=1264616#c4
*
* @param {string} html the html to be stripped of the meta tag.
* @return {string} the cleaned html
*/
function removeCharsetMetaTag( html ) {
const metaTag = `<meta charset='utf-8'>`;

if ( html.startsWith( metaTag ) ) {
return html.slice( metaTag.length );
}

return html;
}