Skip to content

Commit

Permalink
fix(utils): Recognise comments as HTML (#2504)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 authored Apr 30, 2022
1 parent 1eaab1a commit 16dbf20
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/cheerio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ describe('cheerio', () => {
expect(utils.isHtml('<p>fox<p>cat')).toBe(true);
expect(utils.isHtml('\n<p>fox<p>cat\n')).toBe(true);
expect(utils.isHtml('#<p>fox<p>cat#')).toBe(true);
expect(utils.isHtml('<!-- comment -->')).toBe(true);
expect(utils.isHtml('<!doctype html>')).toBe(true);
expect(utils.isHtml('<123>')).toBe(false);
});
});
Expand Down
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

0 comments on commit 16dbf20

Please sign in to comment.