Skip to content

Commit

Permalink
Avoid crash with dynamic aria-label in no-invalid-link-text rule (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanH90 committed Mar 15, 2023
1 parent 184d025 commit 02462a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
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

0 comments on commit 02462a2

Please sign in to comment.