Closed dumbmatter closed 1 year ago
I've confirmed this is an issue (and in typeson core), seemingly confined to top-level objects with the empty string key (probably because the empty string is otherwise used to indicate the root object). I'm surprised this wasn't caught as we do escape even for objects with $types
, but apparently got through. Unfortunately, I'm a bit too preoccupied to look into a fix for this now, and not sure when I might be able to. Should be able to review a PR, however.
I've finally got around to looking into this. I've submitted a PR to fix this at https://github.com/dfahlander/typeson/pull/30 but thought it would be good to confirm it works for you before merging if possible.
There were two issues, both related to the fact that we were internally sometimes using the empty string to refer to the root object and sometimes (kind of) allowing for the empty string.
This PR now should insist that:
$
, e.g., {$: {'': 1234567890}, $types: {$: {'': 'Date'}}}
. (We previously used this escaping mechanism for certain scenarios, but not for the empty-string-as-root scenario.@dumbmatter : Do you think you'll have a chance to take a look relatively soon? Sorry this is quite a while later. I'd like to get the fix out soon, but I think this is unfortunately somewhat of a breaking change, so better to have another pair of eyes on it, even if you're not really familiar with the internals. If not, that's fine; I can just look to release, as it is passing the new tests, and I believe addresses the situation.
@dfahlander : This should, I think, be a breaking change given that the encapsulation format may now necessarily differ, though I expect only a subset of users will be impacted.
I spent 5 minutes trying to get my original example code to run and I'm lost in CJS/ESM issues that I don't want to deal with right now :) regardless, I probably can't say much more than if the tests pass or not.
Thanks @brettz9 🙏
Realized there was a problem with the approach in my previous PR. Experimented and then realized there was a simpler solution which also minimized format changes.
The PR also adds some more examples of the typeson format in the README so people could see more how the format was build, including escaping.
I'll just wait a little in case anyone wants to review, but basically I've just distinguished between a path for whole objects and an empty string path by escaping the empty string as ''
(and then escaping ''
instances as ''''
).
I got this bug report https://github.com/dumbmatter/realistic-structured-clone/issues/8 and somehow didn't notice it until now.
Here's a short script to reproduce:
As you can see...
""
as a key works.new Set()
as a value works. But together, it produces this error.Similar error with
Map
instead ofSet
. In a little testing with other objects, I was not able to trigger the error. Although withnew Date()
it also does something weird:This is with the latest versions of typeson and typeson-registry.