Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fails if object has key of '' #93

Open
tmeasday opened this issue Jan 27, 2023 · 0 comments
Open

[Bug] Fails if object has key of '' #93

tmeasday opened this issue Jan 27, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@tmeasday
Copy link
Member

Describe the bug

These lines:

telejson/src/index.ts

Lines 149 to 150 in 6d2e7a4

// very first iteration
if (key === '') {
assume objects cannot have keys ''. As we saw in storybookjs/storybook#20755, that isn't a good assumption.

Steps to reproduce the behavior

## in node REPL

> const b = {}
undefined

> b[''] = { b: b}
<ref *1> { b: { '': [Circular *1] } }

> require('telejson').stringify(b)
Uncaught TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     <anonymous> -> object with constructor 'Object'
    --- property 'b' closes the circle
    at JSON.stringify (<anonymous>)
    at Object.stringify (/Users/tom/GitHub/chromaui/chromatic/node_modules/telejson/dist/cjs/index.js:467:15)

Expected behavior

It should stringify correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant