Skip to content

fix(crush): preserve values when object keys contain dots#471

Open
kaigritun wants to merge 1 commit intosodiray:masterfrom
kaigritun:fix/crush-dot-keys
Open

fix(crush): preserve values when object keys contain dots#471
kaigritun wants to merge 1 commit intosodiray:masterfrom
kaigritun:fix/crush-dot-keys

Conversation

@kaigritun
Copy link

Problem

When an object contains keys with dots (e.g., 'bar.baz'), the crush function returns undefined for those values:

const foo = {
  key1: { key2: 'value' },
  'bar.baz': 'fiz',
};

crush(foo);
// Result: { 'key1.key2': 'value', 'bar.baz': undefined }
// Expected: { 'key1.key2': 'value', 'bar.baz': 'fiz' }

Root Cause

The crush function used keys() to generate dot-notation paths, then get() to retrieve values. When a key literally contains a dot, get() splits the path by dots and looks for nested properties that don't exist.

Solution

Refactored crush to iterate recursively through the object and directly assign values to the result, rather than using keys() + get(). This preserves the actual value regardless of what characters the key contains.

Changes

  • Modified crush in src/object.ts to use a recursive approach
  • Added test case for keys containing dots

Testing

All existing tests pass, plus the new edge case test.

Fixes #468

When an object contains keys with dots (e.g., 'bar.baz'), the crush function
would return undefined for those values. This happened because crush used
keys() to generate dot-notation paths, then get() to retrieve values. When
a key literally contains a dot, get() would split it and look for nested
properties that don't exist.

Fixed by refactoring crush to iterate recursively through the object and
directly assign values to the result, rather than using keys() + get().

Fixes sodiray#468
@vercel
Copy link

vercel bot commented Feb 12, 2026

Someone is attempting to deploy a commit to the rayunishinedev's projects Team on Vercel.

A member of the Team first needs to authorize it.

@dastanmedetbekov
Copy link

hahaha ai

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.

Values become undefined after applying crush when object keys contain dots

2 participants