-
Notifications
You must be signed in to change notification settings - Fork 794
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
fix: avoid problems from element IDs that exist on object prototype #4060
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,21 @@ describe('axe.utils.findBy', function () { | |
it('should not throw if passed falsey first parameter', function () { | ||
assert.isUndefined(axe.utils.findBy(null, 'id', 'macaque')); | ||
}); | ||
|
||
it('ignores any non-object elements in the array', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test passes even without your changes, might need a different test / setup. |
||
const obj = { | ||
id: 'monkeys', | ||
foo: 'bar' | ||
}; | ||
const array = ['bananas', true, null, 123, obj]; | ||
|
||
assert.equal(axe.utils.findBy(array, 'id', 'monkeys'), obj); | ||
}); | ||
|
||
it('only looks at owned properties', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test also passes without your changes. For this test to work you'll need to create an object whos prototype parent defines the property in question. Something like this: const parent = {
value: 'bananas'
}
const child = Object.create(parent);
var array = [
child,
{
id: 'monkeys',
value: 'bananas'
}
];
assert.deepEqual(axe.utils.findBy(array, 'value', 'bananas'), {
id: 'monkeys',
value: 'bananas'
}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wow, yeah that sure wasn't my best work ever! |
||
const obj1 = { id: 'monkeys', eat: 'bananas' }; | ||
const obj2 = Object.create(obj1); | ||
obj2.id = 'gorillas'; | ||
assert.equal(axe.utils.findBy([obj2, obj1], 'eat', 'bananas'), obj1); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??? How the heck did that happen