Skip to content

fix(parser): recognize attributes without whitespace between quoted values - #1966

Open
draarivpatel-ui wants to merge 1 commit into
htmlhint:mainfrom
draarivpatel-ui:fix/parser-adjacent-quoted-attributes
Open

draarivpatel-ui wants to merge 1 commit into
htmlhint:mainfrom
draarivpatel-ui:fix/parser-adjacent-quoted-attributes

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Short description of what this resolves

Fixes a false tag-pair error reported for valid start tags whose quoted attributes are not separated by whitespace. Closes #1460 (and the older #18).

Given this markup:

<div id="abc"class="def">
    test
</div>

HTMLHint reported Tag must be paired, no start tag: [ </div> ] on the closing tag. The tagstart regex required \s+ before every attribute, so a value ending in a quote followed immediately by the next attribute name made the whole start tag fail to match. The parser then emitted the start tag as plain text, leaving the end tag with no matching start.

Proposed changes

  • Relax the attribute separator in src/core/htmlparser.ts so a new attribute may begin directly after a closing single or double quote, while whitespace stays the normal separator. Malformed tags such as <divclass="x"> are still treated as text, so no existing parsing behavior changes.
  • Regenerate the tracked dist/core/htmlparser.js build output.
  • Add regression tests in test/htmlparser.spec.js (double and single quoted attributes) and test/rules/tag-pair.spec.js (no false pairing error).

Verification

  • npm run lint passes.
  • npm run build passes and leaves a clean tree (git diff --exit-code).
  • npm test passes: 61 suites, 384 tests.

…alues

When a quoted attribute value is immediately followed by another attribute (for example id="abc"class="def"), the tag regex required a whitespace separator before every attribute and therefore failed to match the whole start tag. The tag was emitted as text and tag-pair reported a false no start tag error for the matching end tag. Relax the separator to allow a new attribute directly after a closing quote while keeping whitespace as the normal separator.
Copilot AI balanced review requested due to automatic review settings November 10, 2026 00:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Comment thread src/core/htmlparser.ts
const regTag =
// eslint-disable-next-line no-control-regex
/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g
/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:(?:\s+|(?<=["']))[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g
Comment thread src/core/htmlparser.ts
const regTag =
// eslint-disable-next-line no-control-regex
/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g
/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:(?:\s+|(?<=["']))[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g
@coliff

coliff commented Nov 10, 2026

Copy link
Copy Markdown
Member

Hi @draarivpatel-ui - can you address or comment on the GitHub Advanced Security feedback please?

This branch has not been deployed

No deployments
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.

Error on opening tag flagging error on closing tag saying opening tag is missing

4 participants