fix(lint): do not treat text inside quoted attributes as boolean attribute names (#4381) - #4878
Closed
Adarsh-mk7 wants to merge 1 commit into
Closed
Adarsh-mk7 wants to merge 1 commit into
Adarsh-mk7 wants to merge 1 commit into
Conversation
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Make
hasAttrNamein@hyperframes/lintquote-aware by parsing HTML attributes viahtmlparser2instead of regex matching raw attribute text.Problem and user impact
When an element contains text inside single- or double-quoted attributes (such as
title="an unmuted muted clip"oraria-label="muted"), the linter misinterprets the text inside quotes as amutedattribute.This causes:
video_missing_mutedandvideo_audio_double_sourcediagnostics. In production, unmuted videos that lack audio synchronization or cause audio echo pass lint undetected.crossoriginfalsely triggermedia_crossorigin_breaks_previewand fail validation.Root cause
hasAttrName(tagSource, attr)inpackages/lint/src/rules/media.tsstripped the leading tag name and rannew RegExp((?:^|\s)${escaped}(?:\s*=|\s|/?>), "i")directly over the raw attribute string. Because it did not parse attributes or track quote boundaries, any occurrence of an attribute name within quoted attribute values matched.Solution
Replaced the unquoted regex scan in
hasAttrNamewithhtmlparser2'sParser. This:<video muted>, empty-string attributes<video muted="">, and valued boolean attributes like<video muted="false">).Related work
Fixes #4381
Test plan
mutedcheck, properly reportingvideo_missing_mutedandvideo_audio_double_source.mutedattributes are recognized.crossorigininside a quoted attribute value does not triggermedia_crossorigin_breaks_preview.bun run --cwd packages/lint test src/rules/media.test.ts(all 79 tests pass).oxlint,oxfmt --check, andtsc --noEmitpass with 0 errors.