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

bug: TypeError: Cannot convert object to primitive value #235

Closed
alvaroinckot opened this issue May 21, 2021 · 1 comment · Fixed by #239
Closed

bug: TypeError: Cannot convert object to primitive value #235

alvaroinckot opened this issue May 21, 2021 · 1 comment · Fixed by #239
Assignees
Labels

Comments

@alvaroinckot
Copy link

alvaroinckot commented May 21, 2021

What?

The string validator is in someway evaluating the objects coming as params and it breaks if it has native prototype references (e.g. toString, toJSON)

How to reproduce it?

const Validator = require("fastest-validator");
const v = new Validator();
const schema = {    name: { type: "string" },};
const check = v.compile(schema);

console.log(check({ name: "test"})); // it works, and passes
console.log(check({ name: { "abc": 1 }})); // it works, and rejects
console.log(check({ name: { "toString": 1 }})); // it fails - TypeError: Cannot convert object to primitive value

Environment:

$ node --version
v12.16.1
macOS Catalina 10.15.16
fastest-validator version: 1.11.0

Comments:
I didn't inspect the code deeply, but if you have any suggestions about how to solve it, I will be glad to help!

@icebob
Copy link
Owner

icebob commented May 21, 2021

Thanks the report. Repro link: https://replit.com/@icebob/fastest-validator-235

@icebob icebob added the bug label May 21, 2021
@erfanium erfanium self-assigned this Jun 1, 2021
@erfanium erfanium mentioned this issue Jun 1, 2021
erfanium pushed a commit that referenced this issue Jun 14, 2021
* fix issue 235
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants