From 8fafe7bd9cc421334ef79517bb2c2b51b9390684 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 4 Mar 2022 14:05:09 +0000 Subject: [PATCH] Guard against empty Navigation title --- .../navigation/edit/use-create-navigation-menu.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/block-library/src/navigation/edit/use-create-navigation-menu.js b/packages/block-library/src/navigation/edit/use-create-navigation-menu.js index 41a2fea97420a..346e0e1cdc5d0 100644 --- a/packages/block-library/src/navigation/edit/use-create-navigation-menu.js +++ b/packages/block-library/src/navigation/edit/use-create-navigation-menu.js @@ -28,6 +28,19 @@ export default function useCreateNavigationMenu( clientId ) { // a new navigation menu when the user completes the final step. const create = useCallback( async ( title = null, blocks = [] ) => { + // Guard against creating Navigations without a title. + // Note you can pass no title, but if one is passed it must be + // a string otherwise the title may end up being empty. + if ( title && typeof title !== 'string' ) { + setError( + 'Invalid title supplied when creating Navigation Menu.' + ); + setStatus( ERROR ); + throw new Error( + `Value of supplied title argument was not a string.` + ); + } + setStatus( PENDING ); setValue( null ); setError( null );