msgpack.js icon indicating copy to clipboard operation
msgpack.js copied to clipboard

Serializer also serializes properties in object prototype

Open luisgabrielroldan opened this issue 2 years ago • 1 comments

Looks like a for loop is used for iterating the properties in the objects

for (let key in data) {
	if (data[key] !== undefined) {
		length++;
	}
}

This also iterates the properties defined in prototypes which I don't think is an expected behaviour.

The current typescript version of msgpack is using Object.keys that does not returns those properties.

What do you think?

luisgabrielroldan avatar Feb 01 '23 19:02 luisgabrielroldan

I'm not using prototypes in that area IIRC. So I don't have a strong opinion here. I think I've seen the JSON serializer in .NET also regarding inherited properties, which would roughly translate to the current behaviour regarding the prototype. But if most users agree that this change should be done, then I'm up for it. Maybe let's have a vote on this issue? (But the visitors volume here is generally rather low.)

One question might be whether this is a breaking change or merely a bugfix.

ygoe avatar Feb 01 '23 22:02 ygoe