blitz-js / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
MIT License
3.88k stars 83 forks source link

serialization/deserialization bug #58

Closed benatkin closed 3 years ago

benatkin commented 3 years ago

I think I found a serialization/deserialization bug, for which there isn't an open issue. I ran this against the latest version of superjson about a week ago:

> x = sj.serialize({q: [9, {henlo: undefined, yee: new Date(), yee2: new Date(), foo1: new Date(), z: Symbol('cool')}]})
{
  json: { q: [ 9, [Object] ] },
  meta: {
    values: { 'q.1.henlo': [Array], 'q.1.yee': [Array], 'q.1.foo1': [Array] }
  }
}
> x.json.q
[
  9,
  {
    henlo: undefined,
    yee: '2020-09-06T22:41:57.555Z',
    yee2: '2020-09-06T22:41:57.555Z',
    foo1: '2020-09-06T22:41:57.555Z',
    z: Symbol(cool)
  }
]
> sj.deserialize(x)
{
  q: [
    9,
    {
      henlo: undefined,
      yee: 2020-09-06T22:41:57.555Z,
      yee2: '2020-09-06T22:41:57.555Z',
      foo1: 2020-09-06T22:41:57.555Z,
      z: Symbol(cool)
    }
  ]
}
Skn0tt commented 3 years ago

Thanks for reporting!

If you're talking about the Symbol: You'll need to register it using SuperJSON.registerSymbol before calling serialize. We'll definitely need to document that :D

If not, could you elaborate on what's the bug in this example?

Skn0tt commented 3 years ago

Oh no, you're talking about yee2, right? I can reproduce the bug locally. Will look into it.