From 82463c2ef652205fa3a8c893115863eabe195f3c Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Mon, 26 Jun 2023 02:42:32 -0700 Subject: [PATCH] Fix overview failing to render in some cases with toUpperCase exception (#17021) --- src/common/entity/strip_prefix_from_entity_name.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/common/entity/strip_prefix_from_entity_name.ts b/src/common/entity/strip_prefix_from_entity_name.ts index e976b7b18f..bbb024fa37 100644 --- a/src/common/entity/strip_prefix_from_entity_name.ts +++ b/src/common/entity/strip_prefix_from_entity_name.ts @@ -17,12 +17,13 @@ export const stripPrefixFromEntityName = ( if (lowerCasedEntityName.startsWith(lowerCasedPrefixWithSuffix)) { const newName = entityName.substring(lowerCasedPrefixWithSuffix.length); - - // If first word already has an upper case letter (e.g. from brand name) - // leave as-is, otherwise capitalize the first word. - return hasUpperCase(newName.substr(0, newName.indexOf(" "))) - ? newName - : newName[0].toUpperCase() + newName.slice(1); + if (newName.length) { + // If first word already has an upper case letter (e.g. from brand name) + // leave as-is, otherwise capitalize the first word. + return hasUpperCase(newName.substr(0, newName.indexOf(" "))) + ? newName + : newName[0].toUpperCase() + newName.slice(1); + } } }