diff --git a/packages/editor/src/components/post-title/index.js b/packages/editor/src/components/post-title/index.js index 69308197002d50..781c5ef46d5362 100644 --- a/packages/editor/src/components/post-title/index.js +++ b/packages/editor/src/components/post-title/index.js @@ -149,9 +149,13 @@ function PostTitle( _, forwardedRef ) { plainText, } ); - if ( typeof content !== 'string' && content.length ) { - event.preventDefault(); + event.preventDefault(); + + if ( ! content.length ) { + return; + } + if ( typeof content !== 'string' ) { const [ firstBlock ] = content; if ( @@ -164,6 +168,8 @@ function PostTitle( _, forwardedRef ) { } else { onInsertBlockAfter( content ); } + } else { + onUpdate( content ); } } diff --git a/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-single-line-in-post-title-1-chromium.txt b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-single-line-in-post-title-1-chromium.txt new file mode 100644 index 00000000000000..5e1c309dae7f45 --- /dev/null +++ b/test/e2e/specs/editor/various/__snapshots__/Copy-cut-paste-should-paste-single-line-in-post-title-1-chromium.txt @@ -0,0 +1 @@ +Hello World \ No newline at end of file diff --git a/test/e2e/specs/editor/various/copy-cut-paste.spec.js b/test/e2e/specs/editor/various/copy-cut-paste.spec.js index 030c227e98fe53..87b80495bf5547 100644 --- a/test/e2e/specs/editor/various/copy-cut-paste.spec.js +++ b/test/e2e/specs/editor/various/copy-cut-paste.spec.js @@ -397,4 +397,23 @@ test.describe( 'Copy/cut/paste', () => { await pageUtils.pressKeyWithModifier( 'primary', 'v' ); expect( await editor.getEditedPostContent() ).toMatchSnapshot(); } ); + + test( 'should paste single line in post title', async ( { + page, + pageUtils, + } ) => { + // This test checks whether we are correctly handling single line + // pasting in the post title. Previously we were accidentally falling + // back to default browser behaviour, allowing the browser to insert + // unfiltered HTML. When we swap out the post title in the post editor + // with the proper block, this test can be removed. + await pageUtils.setClipboardData( { + html: 'Hello World', + } ); + await pageUtils.pressKeyWithModifier( 'primary', 'v' ); + // Expect the span to be filtered out. + expect( + await page.evaluate( () => document.activeElement.innerHTML ) + ).toMatchSnapshot(); + } ); } );