fix: allow a single rename to a target named after an Object.prototype member - #3127
Open
spokodev wants to merge 1 commit into
Open
fix: allow a single rename to a target named after an Object.prototype member#3127spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
…e member
internals.rename tracked used rename targets in a plain {}, so the guard
renamed[to] inherited from Object.prototype. For a target colliding with a
prototype member (toString, constructor, __proto__, hasOwnProperty, ...),
renamed['toString'] was truthy on the first rename, so a single legitimate
rename to such a name falsely raised object.rename.multiple.
Use an Object.create(null) map so membership reflects only actual renames.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
internals.rename(lib/types/keys.js) tracks used rename targets in a plain{}, so the guardrenamed[to]inherits fromObject.prototype. When the target name collides with a prototype member (toString,constructor,__proto__,hasOwnProperty,valueOf, ...),renamed['toString']is already truthy on the first rename, so even a single legitimate rename to such a name falsely raisesobject.rename.multiple.This is self-inconsistent:
multipledefaults tofalse, so a single rename must succeed regardless of the target's name. The failure depends only on a name collision with a built-in prototype member.Fix
Build the tracking map with
Object.create(null)so membership reflects only actual renames, not inherited prototype keys.Tests
Added a test for a single rename to a prototype-named target. It fails before the fix (
object.rename.multiple) and passes after. Full suite is green with no leaks. Genuine duplicate-rename detection (two renames to the same target, includingtoString) and override detection are unchanged.