Skip to content

Commit 63d5a1b

Browse files
committed
[Fix] jsx-no-script-url: avoid crash with boolean href
Fixes #2871
1 parent edbbd79 commit 63d5a1b

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1414
* [`display-name`]/component detection: avoid a crash on anonymous components ([#2840][] @ljharb)
1515
* [`prop-types`]: function in class that returns a component causes false warning in typescript ([#2843][] @SyMind)
1616
* [`jsx-no-target-blank`]: avoid a crash with a non-string literal ([#2851][] @ljharb)
17+
* [`jsx-no-script-url`]: avoid crash with boolean `href` ([#2871][] @ljharb)
1718

19+
[#2871]: https://github.com/yannickcr/eslint-plugin-react/issues/2871
1820
[#2851]: https://github.com/yannickcr/eslint-plugin-react/issues/2851
1921
[#2843]: https://github.com/yannickcr/eslint-plugin-react/pull/2843
2022
[#2840]: https://github.com/yannickcr/eslint-plugin-react/issues/2840

lib/rules/jsx-no-script-url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const docsUrl = require('../util/docsUrl');
1616
const isJavaScriptProtocol = /^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*:/i;
1717

1818
function hasJavaScriptProtocol(attr) {
19-
return attr.value.type === 'Literal'
19+
return attr.value && attr.value.type === 'Literal'
2020
&& isJavaScriptProtocol.test(attr.value.value);
2121
}
2222

tests/lib/rules/jsx-no-script-url.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ ruleTester.run('jsx-no-script-url', rule, {
3737
{code: '<a href=""></a>'},
3838
{code: '<a name="foo"></a>'},
3939
{code: '<a href={"javascript:"}></a>'},
40-
{code: '<Foo href="javascript:"></Foo>'}
40+
{code: '<Foo href="javascript:"></Foo>'},
41+
{code: '<a href />'}
4142
],
4243
invalid: [{
4344
code: '<a href="javascript:"></a>',

0 commit comments

Comments
 (0)