File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
packages/block-editor/src/components/rich-text Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments