|
5 | 5 |
|
6 | 6 | 'use strict'; |
7 | 7 |
|
| 8 | +const includes = require('array-includes'); |
8 | 9 | const docsUrl = require('../util/docsUrl'); |
9 | 10 | const linkComponentsUtil = require('../util/linkComponents'); |
10 | 11 | const report = require('../util/report'); |
@@ -48,16 +49,16 @@ function attributeValuePossiblyBlank(attribute) { |
48 | 49 | return false; |
49 | 50 | } |
50 | 51 |
|
51 | | -function hasExternalLink(node, linkAttribute, warnOnSpreadAttributes, spreadAttributeIndex) { |
52 | | - const linkIndex = findLastIndex(node.attributes, (attr) => attr.name && attr.name.name === linkAttribute); |
| 52 | +function hasExternalLink(node, linkAttributes, warnOnSpreadAttributes, spreadAttributeIndex) { |
| 53 | + const linkIndex = findLastIndex(node.attributes, (attr) => attr.name && includes(linkAttributes, attr.name.name)); |
53 | 54 | const foundExternalLink = linkIndex !== -1 && ((attr) => attr.value && attr.value.type === 'Literal' && /^(?:\w+:|\/\/)/.test(attr.value.value))( |
54 | 55 | node.attributes[linkIndex]); |
55 | 56 | return foundExternalLink || (warnOnSpreadAttributes && linkIndex < spreadAttributeIndex); |
56 | 57 | } |
57 | 58 |
|
58 | | -function hasDynamicLink(node, linkAttribute) { |
| 59 | +function hasDynamicLink(node, linkAttributes) { |
59 | 60 | const dynamicLinkIndex = findLastIndex(node.attributes, (attr) => attr.name |
60 | | - && attr.name.name === linkAttribute |
| 61 | + && includes(linkAttributes, attr.name.name) |
61 | 62 | && attr.value |
62 | 63 | && attr.value.type === 'JSXExpressionContainer'); |
63 | 64 | if (dynamicLinkIndex !== -1) { |
@@ -194,9 +195,9 @@ module.exports = { |
194 | 195 | } |
195 | 196 | } |
196 | 197 |
|
197 | | - const linkAttribute = linkComponents.get(node.name.name); |
198 | | - const hasDangerousLink = hasExternalLink(node, linkAttribute, warnOnSpreadAttributes, spreadAttributeIndex) |
199 | | - || (enforceDynamicLinks === 'always' && hasDynamicLink(node, linkAttribute)); |
| 198 | + const linkAttributes = linkComponents.get(node.name.name); |
| 199 | + const hasDangerousLink = hasExternalLink(node, linkAttributes, warnOnSpreadAttributes, spreadAttributeIndex) |
| 200 | + || (enforceDynamicLinks === 'always' && hasDynamicLink(node, linkAttributes)); |
200 | 201 | if (hasDangerousLink && !hasSecureRel(node, allowReferrer, warnOnSpreadAttributes, spreadAttributeIndex)) { |
201 | 202 | const messageId = allowReferrer ? 'noTargetBlankWithoutNoopener' : 'noTargetBlankWithoutNoreferrer'; |
202 | 203 | const relValue = allowReferrer ? 'noopener' : 'noreferrer'; |
@@ -265,11 +266,11 @@ module.exports = { |
265 | 266 | return; |
266 | 267 | } |
267 | 268 |
|
268 | | - const formAttribute = formComponents.get(node.name.name); |
| 269 | + const formAttributes = formComponents.get(node.name.name); |
269 | 270 |
|
270 | 271 | if ( |
271 | | - hasExternalLink(node, formAttribute) |
272 | | - || (enforceDynamicLinks === 'always' && hasDynamicLink(node, formAttribute)) |
| 272 | + hasExternalLink(node, formAttributes) |
| 273 | + || (enforceDynamicLinks === 'always' && hasDynamicLink(node, formAttributes)) |
273 | 274 | ) { |
274 | 275 | const messageId = allowReferrer ? 'noTargetBlankWithoutNoopener' : 'noTargetBlankWithoutNoreferrer'; |
275 | 276 | report(context, messages[messageId], messageId, { |
|
0 commit comments