Skip to content
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: resolves issue proto-less object validation #6884

Merged
merged 2 commits into from
Oct 12, 2020

Conversation

maayanbar13
Copy link
Contributor

Due to instanceof comparison, object without prototype is mistaken for a privative value, throwing TypeError: Cannot convert object to primitive value. when trying to .toString said object (inside template string).

This mostly effects usage with graphql as graphql-js, by design, creates objects by using Object.create(null).
This fix allows saving these objects.

The fix uses typeof instead of toString comparison since I see no reason why new Number/Boolean/Date should be a supported use case.

Closes: #2065

@imnotjames
Copy link
Contributor

Can you create tests that verify this fixes the erroneous behavior?

@maayanbar13
Copy link
Contributor Author

@imnotjames Added tests :)

Copy link
Contributor

@imnotjames imnotjames left a comment

Choose a reason for hiding this comment

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

This makes sense to me. Doesn't seem to introduce any backwards compatibility issues. Has tests. Wonderful!

@imnotjames imnotjames added the hacktoberfest-accepted label hacktoberfest label Oct 12, 2020
@imnotjames imnotjames merged commit e08d9c6 into typeorm:master Oct 12, 2020
@imnotjames
Copy link
Contributor

Thanks for the contribution and fixing this long outstanding issue :)

zaro pushed a commit to zaro/typeorm that referenced this pull request Jan 12, 2021
Due to `instanceof` comparison, object without prototype is mistaken for a privative value, throwing `TypeError: Cannot convert object to primitive value.` when trying to `.toString` said object (inside template string).

This mostly effects usage with `graphql` as `graphql-js`, [by design](graphql/graphql-js#504), creates objects by using Object.create(null).
This fix allows saving these objects.    

The fix uses `typeof` instead of `toString` comparison since I see no reason why `new Number/Boolean/Date` should be a supported use case.

Closes: typeorm#2065
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted label hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Cannot convert object to primitive value
2 participants