Skip to content

Improve robustness of options.type#10

Merged
sindresorhus merged 3 commits intosindresorhus:mainfrom
aaronccasanova:patch-1
Jun 6, 2022
Merged

Improve robustness of options.type#10
sindresorhus merged 3 commits intosindresorhus:mainfrom
aaronccasanova:patch-1

Conversation

@aaronccasanova
Copy link
Copy Markdown
Contributor

@aaronccasanova aaronccasanova commented Jun 5, 2022

Updated checkType to only allow type properties on the typeMappings object (as opposed to any property down the prototype chain). Removed type === undefined check in matchType as options.type is validated at the top of both sync and async APIs to be file or directory. I ran npm test locally with no issues, but feel free to close if I'm missing something.

aaronccasanova and others added 2 commits June 5, 2022 09:51
The `type` option is validated at the top of both sync and async APIs. I ran `npm test` locally with no issues, but feel free to close if I'm missing something.

function checkType(type) {
if (type in typeMappings) {
if (Object.hasOwnProperty.call(typeMappings, type)) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Was it intentional to look down the prototype chain?

I would expect this to be an invalid type error: await locatePath(files, 'toString');
image

typeMappings.hasOwnProperty may be more appropriate:
image

@aaronccasanova aaronccasanova changed the title Remove type check in the matchType utility Improve robustness of options.type Jun 5, 2022
@sindresorhus sindresorhus merged commit 6afde95 into sindresorhus:main Jun 6, 2022
@sindresorhus
Copy link
Copy Markdown
Owner

Thanks :)

@aaronccasanova aaronccasanova deleted the patch-1 branch June 6, 2022 03:49
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