Skip to content

fix(compat/pick): prioritize literal key over dot notation path when value is undefined - #1775

Merged
raon0211 merged 2 commits into
toss:mainfrom
Antoliny0919:fix-compat-pick
Jun 24, 2026
Merged

raon0211 merged 2 commits into
toss:mainfrom
Antoliny0919:fix-compat-pick

Conversation

@Antoliny0919

Copy link
Copy Markdown
Contributor

Summary

In pick, when using dot notation, a literal key matching the dot-notation path takes priority, as documented.

스크린샷 2026-06-13 오후 9 43 10

However, there is a bug where the literal key is ignored when its value is undefined.

Reproduce

import { pick as loPick } from 'lodash';
import { pick as esCompatPick } from './src/compat/object/pick';

const pickObj = { 'a.b': undefined, a: { b: 99 } };

console.log(loPick(pickObj, 'a.b')); // { 'a.b': undefined }
console.log(esCompatPick(pickObj, 'a.b')); // { 'a.b': 99 }

@vercel

vercel Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
es-toolkit Ready Ready Preview, Comment Jun 23, 2026 5:08am

Request Review

@raon0211

raon0211 commented Jun 16, 2026 •

Copy link
Copy Markdown
Collaborator

Looking at the code, I think there's probably a bug in get too (since in pick we set the value we got from get), so we should fix that as well.

@Antoliny0919

Copy link
Copy Markdown
Contributor Author

Looking at the code, I think there's probably a bug in get too (since in pick we set the value we got from get), so we should fix that as well.

Thanks for pointing that out! I'll take a look over the weekend 👍

@raon0211 raon0211 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@raon0211
raon0211 merged commit 6bbf178 into toss:main Jun 24, 2026
10 checks passed
raon0211 added a commit that referenced this pull request Jun 27, 2026
…unset (match #1775) (#1808)

* fix(compat/unset): prioritize literal key over dot-notation path when value is undefined

When an object has an own key containing dots (e.g. 'a.b') whose value is
undefined, unset() incorrectly fell through to the deep-path branch and
deleted the nested a.b instead of the literal 'a.b' key, leaving the literal
key in place. This mirrors the literal-key-over-path fix applied to get()/pick()
in #1775; add the same !Object.hasOwn(obj, path) guard so unset() (and omit(),
which delegates to it) match lodash.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Apply suggestions from code review

Co-authored-by: Sojin Park <raon0211@gmail.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Sojin Park <raon0211@gmail.com>

This branch was successfully deployed

1 active deployment
Preview — be2d0077 Deployed Jun 23, 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.

2 participants