Skip to content

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

Closed
@alvaroinckot

Description

@alvaroinckot

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!

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions