kiliman / remix-typedjson

This package is a replacement for superjson to use in your Remix app. It handles a subset of types that `superjson` supports, but is faster and smaller.
MIT License
435 stars 19 forks source link

Meta keys can be incorrect when there is an empty string property #33

Open ericallam opened 10 months ago

ericallam commented 10 months ago

Recently tracked down this weird edge case where there is a nested object with a key that is an empty string and the value is [{}] resulting in meta keys being incorrect after the serialization encounters it. I've added this test case that recreates it.

The offending data here:

const edgeCase = { 
 nested: {
    '': [{}],
     bigint: BigInt(1),
  },
}

The expected value is

'{"nested":{"":[{}],"bigint":"1"},"__meta__":{"nested.bigint":"bigint"}}'

But the actual is:

'{"nested":{"":[{}],"bigint":"1"},"__meta__":{"bigint":"bigint"}}'

My guess is that there is somewhere doing a conditional on the "" value which will return false.

valstu commented 10 months ago

So you beat me at debugging, came here to make the exact same issue 😄

kiliman commented 10 months ago

Thanks for the bug report. I never considered empty keys before.