From e54118b5c8523e885972748e9b48f64f30d57d58 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Tue, 16 Feb 2021 10:29:30 -0500 Subject: [PATCH] [Fix] `jsx-no-target-blank`: Allow rel="noreferrer" when `allowReferrer` is true --- CHANGELOG.md | 2 ++ lib/rules/jsx-no-target-blank.js | 6 +++++- tests/lib/rules/jsx-no-target-blank.js | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d499abf0dd..85db74365e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel * [`no-typos`]: avoid a crash on bindingless `prop-types` import; add warning ([#2899][] @ljharb) * [`jsx-curly-brace-presence`]: ignore containers with comments ([#2900][] @golopot) * [`destructuring-assignment`]: fix a false positive for local prop named `context` in SFC ([#2929][] @SyMind) +* [`jsx-no-target-blank`]: Allow rel="noreferrer" when `allowReferrer` is true ([#2925][] @edemaine) ### Changed * [Docs] [`jsx-no-constructed-context-values`][]: fix invalid example syntax ([#2910][] @kud) @@ -24,6 +25,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel * [Docs] added missing curly braces ([#2923][] @Muditxofficial) [#2929]: https://github.com/yannickcr/eslint-plugin-react/pull/2929 +[#2925]: https://github.com/yannickcr/eslint-plugin-react/pull/2925 [#2923]: https://github.com/yannickcr/eslint-plugin-react/pull/2923 [#2910]: https://github.com/yannickcr/eslint-plugin-react/pull/2910 [#2908]: https://github.com/yannickcr/eslint-plugin-react/pull/2908 diff --git a/lib/rules/jsx-no-target-blank.js b/lib/rules/jsx-no-target-blank.js index cd59296de7..6ce338bff2 100644 --- a/lib/rules/jsx-no-target-blank.js +++ b/lib/rules/jsx-no-target-blank.js @@ -88,7 +88,11 @@ function hasSecureRel(node, allowReferrer, warnOnSpreadAttributes, spreadAttribu const relAttribute = node.attributes[relIndex]; const value = getStringFromValue(relAttribute.value); const tags = value && typeof value === 'string' && value.toLowerCase().split(' '); - return tags && (allowReferrer ? tags.indexOf('noopener') >= 0 : tags.indexOf('noreferrer') >= 0); + const noreferrer = tags && tags.indexOf('noreferrer') >= 0; + if (noreferrer) { + return true; + } + return allowReferrer && tags && tags.indexOf('noopener') >= 0; } module.exports = { diff --git a/tests/lib/rules/jsx-no-target-blank.js b/tests/lib/rules/jsx-no-target-blank.js index b845ba60dd..703168aef1 100644 --- a/tests/lib/rules/jsx-no-target-blank.js +++ b/tests/lib/rules/jsx-no-target-blank.js @@ -103,6 +103,10 @@ ruleTester.run('jsx-no-target-blank', rule, { code: '', options: [{allowReferrer: true}] }, + { + code: '', + options: [{allowReferrer: true}] + }, { code: '' } @@ -212,6 +216,12 @@ ruleTester.run('jsx-no-target-blank', rule, { output: '', errors: defaultErrors }, + { + code: '', + output: '', + options: [{allowReferrer: true}], + errors: defaultErrors + }, { code: '', output: '',