Skip to content

fix(countBy): prevent prototype property collisions when counting - #2222

Open
TbhVishal wants to merge 2 commits into
toss:mainfrom
TbhVishal:fix/countby-prototype-properties
Open

TbhVishal wants to merge 2 commits into
toss:mainfrom
TbhVishal:fix/countby-prototype-properties

Conversation

@TbhVishal

@TbhVishal TbhVishal commented Nov 15, 2026 •

Copy link
Copy Markdown

Fixes #2218

When keys match built-in Object properties like 'toString' or 'constructor', counting into a plain object collides with the prototype. Changed the accumulator to Object.create(null) so property lookups stay clean.

Tested with pnpm test packages/es-toolkit/src/array/countBy.spec.ts, let me know if any tweaks are needed.

@vercel

vercel Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
es-toolkit Ready Ready Preview Nov 15, 2026 7:55pm UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — d532fd4f Deployed Nov 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compat: matchesProperty matches wrong values, and merge aliases source objects over primitive targets

1 participant