Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crash with dynamic aria-label in no-invalid-link-text rule #2843

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rules/no-invalid-link-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ function hasValidAriaLabel(node) {
const ariaLabelAttr = AstNodeInfo.findAttribute(node, 'aria-label');

if (ariaLabelAttr) {
if (ariaLabelAttr.value?.type === 'MustacheStatement') {
// We can't evaluate MustacheStatements so we assume this is valid
return true;
}
let ariaLabel = getTrimmedText(ariaLabelAttr.value.chars);
return !DISALLOWED_LINK_TEXT.has(ariaLabel);
}
Expand Down
2 changes: 2 additions & 0 deletions test/unit/rules/no-invalid-link-text-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ generateRuleTests({
'<a href="https://myurl.com" aria-label="click here to read about our company"></a>',
'<a href="https://myurl.com" aria-hidden="true"></a>',
'<a href="https://myurl.com" hidden></a>',
'<LinkTo aria-label={{t "some-translation"}}>A link with translation</LinkTo>',
'<a href="#" aria-label={{this.anAriaLabel}}>A link with a variable as aria-label</a>',
{
config: { allowEmptyLinks: true },
template: '<a href="https://myurl.com"></a>',
Expand Down