gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Validate or handle undefined block title

Open aduth opened this issue 9 years ago • 1 comments

Issue Overview

When a registered block omits its title property, the editor crashes when searching the Inserter Menu.

Steps to Reproduce (for bugs)

  1. Navigate to Gutenberg > New Post
  2. Insert the following snippet in your browser Developer Tools console to register the problematic block type
    • wp.blocks.registerBlockType( 'core/demo', { edit: () => '', save: () => '' } );
  3. Toggle one of the inserters
  4. Start searching

Expected Behavior

Search occurs.

Current Behavior

The editor crashes.

Uncaught TypeError: Cannot read property 'toLowerCase' of undefined

Possible Solution

Block registration already includes a number of validation checks. We could augment with another check to verify that the title is usable:

https://github.com/WordPress/gutenberg/blob/e5130c3/blocks/api/registration.js#L39-L79

Alternatively, we could allow the block to be registered but not appear in the inserter when searched for by testing whether the block has a title before performing toLowerCase.

aduth avatar Aug 07 '17 14:08 aduth

I've added some additional validation to verify the block title and updated the test-unit accordingly.

kuoko avatar Sep 13 '17 11:09 kuoko