Skip to content

Return default value if path is invalid#86

Merged
sindresorhus merged 6 commits intosindresorhus:mainfrom
Richienb:default-value-invalid
Sep 8, 2021
Merged

Return default value if path is invalid#86
sindresorhus merged 6 commits intosindresorhus:mainfrom
Richienb:default-value-invalid

Conversation

@Richienb
Copy link
Contributor

@Richienb Richienb commented Sep 8, 2021

This is the last untested part of the code (#70)

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
@Richienb Richienb mentioned this pull request Sep 8, 2021
@Richienb Richienb changed the title Return default value if invalid path provided Return default value if path is invalid Sep 8, 2021
@sindresorhus
Copy link
Owner

Can you do a new test (with a descriptive title)

Test, not assertion.

test.js Outdated

test('return default value if path is invalid', t => {
t.is(dotProp.get({}, '__proto__', '🦄'), '🦄');
t.is(dotProp.get({}, 'nonexistent', '🦄'), '🦄');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path is only "invalid" if a disallowed property is passed. Testing for a legal property is already tested for.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other non-legal value we could use that is not __proto__?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dot-prop/index.js

Lines 5 to 7 in 09adad9

'__proto__',
'prototype',
'constructor'

@sindresorhus sindresorhus merged commit d400c8d into sindresorhus:main Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants