Skip to content

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

@tmeasday

Description

@tmeasday

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions