Skip to content

Objects with null prototype are not merged #48

@its-dibo

Description

@its-dibo

I cannot replicate the issue, because I don't know how to create a null-prototype object.

in nestJs interceptor

 let req = context.switchToHttp().getRequest();
console.log(req.query); // Empty <[Object: null prototype] {}>{ x: 1 }

I don't know exactly how req.query is created, may be by Object.create() or by a library like qs or querystring or something else

however, objects like that are not merged, but totally replaces other objects

let query = { y:1 }
merge(query, req.query); // Empty <[Object: null prototype] {}>{ x: 1 }

but this works fine

let query = { y:1 }
merge(query, {...req.query}); // {x: 1, y: 1}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions