diff --git a/src/utils.ts b/src/utils.ts index d2e0caa809..093618fffe 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -93,23 +93,27 @@ export function cloneDom(dom: T | T[]): T[] { return clone; } -/** - * A simple way to check for HTML strings. Tests for a `<` within a string, - * immediate followed by a letter and eventually followed by a `>`. - * - * @private - */ -const quickExpr = /<[a-zA-Z][^]*>/; - /** * Check if string is HTML. * + * Tests for a `<` within a string, immediate followed by a letter and + * eventually followed by a `>`. + * * @private * @category Utils * @param str - String to check. * @returns Indicates if `str` is HTML. */ export function isHtml(str: string): boolean { - // Run the regex - return quickExpr.test(str); + const tagStart = str.indexOf('<'); + + if (tagStart < 0 || tagStart > str.length - 3) return false; + + const tagChar = str.charAt(tagStart + 1); + + return ( + ((tagChar >= 'a' && tagChar <= 'z') || + (tagChar >= 'A' && tagChar <= 'Z')) && + str.includes('>', tagStart + 2) + ); }