Skip to content

Conversation

@joelzanden
Copy link

@joelzanden joelzanden commented Jan 12, 2025

When the input html is malformed and the number of end tags exceed the number of opening tags, level will go negative. That will cause spanLevel to become negative, causing indent.repeat(spanLevel) to throw a RangeError.

By making sure level clamps at 0, this i avoided.

Copy link
Owner

@mohd-akram mohd-akram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test as well? Also, combine your commits. Thank you.

const tagName = token.groups.endTagName.toLowerCase();
if (tagName == specialElement) specialElement = null;
if (!specialElement) {
--level;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the check here instead:

Suggested change
--level;
if (level > 0) --level;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants