Skip to content

fix(compat/toPath): keep empty segments for consecutive and trailing dots - #1778

Merged
raon0211 merged 1 commit into
toss:mainfrom
sarathfrancis90:fix-compat-topath-empty-segments
Jun 19, 2026
Merged

raon0211 merged 1 commit into
toss:mainfrom
sarathfrancis90:fix-compat-topath-empty-segments

Conversation

@sarathfrancis90

Copy link
Copy Markdown
Contributor

Summary

compat/toPath drops empty segments that lodash keeps, so consecutive or
trailing dots resolve differently. toPath('a..b') returns ['a', 'b']
instead of lodash's ['a', '', 'b'], and toPath('a.') returns ['a']
instead of ['a', ''].

Since get/set/has/unset/invokeMap parse string paths through
toPath, this makes an empty-string key in the middle of a path
unreachable when migrating from lodash:

get({ a: { '': { b: 1 } } }, 'a..b'); // lodash: 1, es-toolkit: undefined

Changes

  • Emit an empty segment when a dot is directly followed by another dot or
    by the end of the string (matching lodash's stringToPath).
  • Let the leading dot fall through to the main loop so it is still treated
    as a separator ('..a' -> ['', '', 'a']).
  • Updated invokeMap's "string path" test, which asserted the old
    divergent result for 'a..c'; lodash invokes through the empty-string
    key, so it now expects that.

Test results

yarn vitest run src/compat — 300 files, 3099 passed, 2 skipped.

…dots

toPath dropped empty path segments produced by consecutive dots or a
trailing dot, so 'a..b' became ['a', 'b'] instead of lodash's
['a', '', 'b'] and 'a.' became ['a'] instead of ['a', '']. Because
get/set/has/unset/invokeMap parse string paths through toPath, an
empty-string key in the middle of a path ('a..b' on { a: { '': ... } })
was unreachable.

Emit the empty segment when a dot is directly followed by another dot or
the end of the string, and let the leading dot fall through to the main
loop so it is still treated as a separator.
@vercel

vercel Bot commented Jun 19, 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 19, 2026 4:52am

Request Review

@raon0211
raon0211 merged commit 27fa680 into toss:main Jun 19, 2026
10 checks passed

This branch was successfully deployed

1 active deployment
Preview — 44105cc2 Deployed Jun 19, 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