From 16dbf20d93d710f1f94931b4c4ce434dba5ee9d8 Mon Sep 17 00:00:00 2001 From: Felix <188768+fb55@users.noreply.github.com> Date: Sat, 30 Apr 2022 18:07:13 +0100 Subject: [PATCH] fix(utils): Recognise comments as HTML (#2504) --- src/cheerio.spec.ts | 2 ++ src/utils.ts | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cheerio.spec.ts b/src/cheerio.spec.ts index 89d6e0b2ca..ef4f19b83d 100644 --- a/src/cheerio.spec.ts +++ b/src/cheerio.spec.ts @@ -443,6 +443,8 @@ describe('cheerio', () => { expect(utils.isHtml('

fox

cat')).toBe(true); expect(utils.isHtml('\n

fox

cat\n')).toBe(true); expect(utils.isHtml('#

fox

cat#')).toBe(true); + expect(utils.isHtml('')).toBe(true); + expect(utils.isHtml('')).toBe(true); expect(utils.isHtml('<123>')).toBe(false); }); }); diff --git a/src/utils.ts b/src/utils.ts index c343927bdd..88f65930ee 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -113,7 +113,8 @@ export function isHtml(str: string): boolean { return ( ((tagChar >= 'a' && tagChar <= 'z') || - (tagChar >= 'A' && tagChar <= 'Z')) && + (tagChar >= 'A' && tagChar <= 'Z') || + tagChar === '!') && str.includes('>', tagStart + 2) ); }