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

jsx-no-target-blank -> hasExternalLink does not handle attr.value of null #3066

Closed
gaz77a opened this issue Sep 2, 2021 · 2 comments
Closed
Labels

Comments

@gaz77a
Copy link
Contributor

gaz77a commented Sep 2, 2021

Scenario

Add the following test to the valid section of test/lib/rules/jsx-no-target-blank.js
{code: '<a href target="_blank"/>'},

Symptoms

The following error occurs
TypeError: Cannot read property 'type' of null

Resolution

Add attr.value && before attr.value.type === 'Literal'

here is the updated function
function hasExternalLink(node, linkAttribute, warnOnSpreadAttributes, spreadAttributeIndex) { const linkIndex = findLastIndex(node.attributes, (attr) => attr.name && attr.name.name === linkAttribute); const foundExternalLink = linkIndex !== -1 && ((attr) => attr.value && attr.value.type === 'Literal' && /^(?:\w+:|\/\/)/.test(attr.value.value))( node.attributes[linkIndex]); return foundExternalLink || (warnOnSpreadAttributes && linkIndex < spreadAttributeIndex); }

@ljharb
Copy link
Member

ljharb commented Sep 2, 2021

Thanks!

@ljharb ljharb added the bug label Sep 2, 2021
@ljharb ljharb closed this as completed in 952a768 Sep 2, 2021
@gaz77a
Copy link
Contributor Author

gaz77a commented Sep 3, 2021

my pleasure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants