Skip to content

Commit 9987e21

Browse files
getdavenoisysocks
authored andcommitted
Strip meta tags from pasted links in Chromium (#36356)
* Strip meta tag * Corrections for accuracy * Simply by avoiding regex
1 parent 13be518 commit 9987e21

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/block-editor/src/components/rich-text/use-paste-handler.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export function usePasteHandler( props ) {
9191
// Remove Windows-specific metadata appended within copied HTML text.
9292
html = removeWindowsFragments( html );
9393

94+
// Strip meta tag.
95+
html = removeCharsetMetaTag( html );
96+
9497
event.preventDefault();
9598

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

258261
return html.replace( startReg, '' ).replace( endReg, '' );
259262
}
263+
264+
/**
265+
* Removes the charset meta tag inserted by Chromium.
266+
* See:
267+
* - https://github.com/WordPress/gutenberg/issues/33585
268+
* - https://bugs.chromium.org/p/chromium/issues/detail?id=1264616#c4
269+
*
270+
* @param {string} html the html to be stripped of the meta tag.
271+
* @return {string} the cleaned html
272+
*/
273+
function removeCharsetMetaTag( html ) {
274+
const metaTag = `<meta charset='utf-8'>`;
275+
276+
if ( html.startsWith( metaTag ) ) {
277+
return html.slice( metaTag.length );
278+
}
279+
280+
return html;
281+
}

0 commit comments

Comments
 (0)