fix: support unquoted aria-hidden value in require-alt-text - #719
Open
KumJungMin wants to merge 2 commits into
Open
fix: support unquoted aria-hidden value in require-alt-text#719KumJungMin wants to merge 2 commits into
KumJungMin wants to merge 2 commits into
Conversation
3 tasks
DMartens
reviewed
Aug 18, 2026
|
|
||
| const imgTagPattern = /<img(?:\s(?:[^>"']|"[^"]*"|'[^']*')*)?\/?>/giu; | ||
| const ariaHiddenTruePattern = | ||
| /\saria-hidden\s*=\s*(?:"true"|'true'|true)(?=\s|\/?>)/iu; |
Contributor
There was a problem hiding this comment.
There does not have to be whitespace around an HTML attribute, e.g. <a before="true"aria-hidden="true"after="true"></a> is valid.
In other words the before "aria-hidden" can be a quote or whitespace and alpha characters if the attribute value is quoted.
Contributor
Author
There was a problem hiding this comment.
I’d like to update it as follows to account for the additional cases.
| Case | Before | After | Reason |
|---|---|---|---|
| Boundary before aria-hidden | \s | (?:\s|["']) | Allows aria-hidden to be preceded not only by whitespace, but also directly by the closing quote (" or ') of the previous attribute. |
| Boundary after true | (?:"true"|'true'|true)(?=\s|/?>) | (?:"true"|'true'|true(?=\s|/?>)) | Allows another attribute to immediately follow "true" or 'true' without whitespace, while keeping the existing boundary check for unquoted true so that cases like aria-hidden=truefoo are not matched incorrectly. |
I’m thinking of updating the final pattern as follows. Is there any case I may have misunderstood? (https://regexr.com/8o87r)
/(?:\s|["'])aria-hidden\s*=\s*(?:"true"|'true'|true(?=\s|\/?>))/iu
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.
Prerequisites checklist
AI acknowledgment
What is the purpose of this pull request?
This PR updates require-alt-text to recognize an unquoted aria-hidden=true attribute.
HTML permits attribute values to be written without quotes, but the existing implementation handles the following forms differently:
Since both forms set the value of aria-hidden to true, this PR updates the rule to skip the alternative text check in both cases.
What changes did you make? (Give an overview)
aria-hidden=trueattributes.aria-hidden=truearia-hidden = trueARIA-HIDDEN=TRUEaria-hidden=falseandaria-hidden=truefooare still reported.The regex test cases for this change are available on RegExr.
Related Issues
fixes #718
Is there anything you'd like reviewers to focus on?
To keep the scope of this change minimal, the implementation adds a dedicated regular expression for detecting
aria-hidden=trueinstead of extendinggetHtmlAttributeRe().There are two reasons for this approach:
altattribute parsing behavior and avoids recreating thearia-hiddenregular expression each time an image tag is processed.aria-hiddenrequires checking whether its value is exactlytrue, whilegetHtmlAttributeRe("alt")captures the value of thealtattribute to determine whether it consists only of whitespace. I considered these attributes to have different validation purposes and criteria.I would appreciate feedback on whether this dedicated regular expression is appropriate or whether it would be better to generalize
getHtmlAttributeRe()to handle both quoted and unquoted attribute values. :)