diff --git a/packages/wordcount/src/index.js b/packages/wordcount/src/index.js index a21ab44d1eacb..cf29a91e2088d 100644 --- a/packages/wordcount/src/index.js +++ b/packages/wordcount/src/index.js @@ -95,10 +95,10 @@ export function count( text, type, userSettings ) { const settings = loadSettings( type, userSettings ); if ( text ) { let matchRegExp = settings[ type + 'RegExp' ]; - if ( 'words' === settings.type ) { - return matchWords( text, matchRegExp, settings ).length; - } else { - return matchCharacters( text, matchRegExp, settings ).length; - } + const results = ( 'words' === settings.type ) ? + matchWords( text, matchRegExp, settings ) : + matchCharacters( text, matchRegExp, settings ); + + return results ? results.length : 0; } } diff --git a/packages/wordcount/src/test/index.test.js b/packages/wordcount/src/test/index.test.js index ddabdd133e082..afaee5c8beaa3 100644 --- a/packages/wordcount/src/test/index.test.js +++ b/packages/wordcount/src/test/index.test.js @@ -84,6 +84,13 @@ describe( 'WordCounter', () => { words: 1, characters_excluding_spaces: 5, characters_including_spaces: 6 + }, + { + message: "Empty Tags", + string: "<p></p>", + words: 0, + characters_excluding_spaces: 0, + characters_including_spaces: 0 } ];