Skip to content

Commit

Permalink
List block: prevent error upon pasting when list is empty (#43761)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Sep 1, 2022
1 parent b8b6edb commit 9e1717c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/block-library/src/list/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function createListBlockFromDOMElement( listElement ) {
const [ nestedList, ...nodes ] = children;

const hasNestedList =
nestedList.tagName === 'UL' || nestedList.tagName === 'OL';
nestedList?.tagName === 'UL' || nestedList?.tagName === 'OL';
if ( ! hasNestedList ) {
return createBlock( 'core/list-item', {
content: listItem.innerHTML,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- wp:list -->
<ul><!-- wp:list-item -->
<li></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->
21 changes: 21 additions & 0 deletions test/e2e/specs/editor/blocks/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1132,4 +1132,25 @@ test.describe( 'List', () => {
<!-- /wp:list -->`
);
} );

test( 'can be created by pasting an empty list', async ( {
editor,
pageUtils,
} ) => {
// Open code editor
await pageUtils.pressKeyWithModifier( 'secondary', 'M' ); // Emulates CTRL+Shift+Alt + M => toggle code editor

// Paste empty list block
await pageUtils.setClipboardData( {
plainText:
'<!-- wp:list -->\n<ul><li></li></ul>\n<!-- /wp:list -->',
} );
await pageUtils.pressKeyWithModifier( 'primary', 'v' );

// Go back to normal editor
await pageUtils.pressKeyWithModifier( 'secondary', 'M' ); // Emulates CTRL+Shift+Alt + M => toggle code editor

// Verify no WSOD and content is proper.
expect( await editor.getEditedPostContent() ).toMatchSnapshot();
} );
} );

0 comments on commit 9e1717c

Please sign in to comment.