Skip to content

Commit

Permalink
Post title: fix single line paste (#42321)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Jul 15, 2022
1 parent 40ba2c9 commit 6964324
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/editor/src/components/post-title/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -164,6 +168,8 @@ function PostTitle( _, forwardedRef ) {
} else {
onInsertBlockAfter( content );
}
} else {
onUpdate( content );
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
19 changes: 19 additions & 0 deletions test/e2e/specs/editor/various/copy-cut-paste.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<span style="border: 1px solid black">Hello World</span>',
} );
await pageUtils.pressKeyWithModifier( 'primary', 'v' );
// Expect the span to be filtered out.
expect(
await page.evaluate( () => document.activeElement.innerHTML )
).toMatchSnapshot();
} );
} );

0 comments on commit 6964324

Please sign in to comment.