Skip to content

Commit 23da1ee

Browse files
committed
[Fix] no-unknown-property: avoid crash with prop named with Object.prototype key
Fixes #2879
1 parent 9c1e652 commit 23da1ee

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1818
* [`jsx-no-script-url`]: avoid crash with boolean `href` ([#2871][] @ljharb, @AriPerkkio)
1919
* [`no-typos`]: avoid crash with computed method name ([#2870][] @ljharb, @AriPerkkio)
2020
* [`jsx-max-depth`]: avoid crash with childless jsx child ([#2869][] @ljharb, @AriPerkkio)
21+
* [`no-unknown-property`]: avoid crash with prop named with Object.prototype key ([#2879][] @ljharb, @AriPerkkio)
2122

22-
[#2871]: https://github.com/yannickcr/eslint-plugin-react/issues/2875
23+
[#2879]: https://github.com/yannickcr/eslint-plugin-react/issues/2879
24+
[#2875]: https://github.com/yannickcr/eslint-plugin-react/issues/2875
2325
[#2871]: https://github.com/yannickcr/eslint-plugin-react/issues/2871
2426
[#2870]: https://github.com/yannickcr/eslint-plugin-react/issues/2870
2527
[#2869]: https://github.com/yannickcr/eslint-plugin-react/issues/2869

lib/rules/no-unknown-property.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
'use strict';
77

8+
const has = require('has');
89
const docsUrl = require('../util/docsUrl');
910
const versionUtil = require('../util/version');
1011

@@ -198,10 +199,10 @@ function tagNameHasDot(node) {
198199
* @returns {String | undefined} The standard name of the attribute, or undefined if no standard name was found.
199200
*/
200201
function getStandardName(name, context) {
201-
if (DOM_ATTRIBUTE_NAMES[name]) {
202+
if (has(DOM_ATTRIBUTE_NAMES, name)) {
202203
return DOM_ATTRIBUTE_NAMES[name];
203204
}
204-
if (SVGDOM_ATTRIBUTE_NAMES[name]) {
205+
if (has(SVGDOM_ATTRIBUTE_NAMES, name)) {
205206
return SVGDOM_ATTRIBUTE_NAMES[name];
206207
}
207208
const names = getDOMPropertyNames(context);
@@ -258,7 +259,7 @@ module.exports = {
258259
const tagName = getTagName(node);
259260

260261
// 1. Some attributes are allowed on some tags only.
261-
const allowedTags = ATTRIBUTE_TAGS_MAP[name];
262+
const allowedTags = has(ATTRIBUTE_TAGS_MAP, name) ? ATTRIBUTE_TAGS_MAP[name] : null;
262263
if (tagName && allowedTags && /[^A-Z]/.test(tagName.charAt(0)) && allowedTags.indexOf(tagName) === -1) {
263264
context.report({
264265
node,

tests/lib/rules/no-unknown-property.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ ruleTester.run('no-unknown-property', rule, {
4646
options: [{ignore: ['class']}]
4747
},
4848
{code: '<script crossOrigin />'},
49-
{code: '<audio crossOrigin />'}
49+
{code: '<audio crossOrigin />'},
50+
{code: '<div hasOwnProperty="should not be allowed tag" />'}
5051
],
5152
invalid: [{
5253
code: '<div class="bar"></div>;',

0 commit comments

Comments
 (0)