blakeembrey / blakeembrey/javascript-stringify

Repeated references in Maps & Sets produce broken output

オープン
#34 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
TypeScript
スター
146
フォーク
16
PR マージ指標
30日以内にマージされた PR はありません

説明

Briefly, this happens:

```js
const obj = {}
const map = new Map([['a', obj], ['b', obj]])
const ok = stringify(map)
// "new Map([['a',{}],['b',{}]])"
const bad = stringify(map, null, null, { references: true })
// "(function(){var x=new Map([['a',{}],['b',undefined]]);x[1][1]=x[0][1];return x;}())"
eval(bad)
// Uncaught TypeError: Cannot read property '1' of undefined
```

The problem here is that the object type isn't tracked, and therefore isn't taken into account by `stringifyPath`. The `.` and `[]` forms work fine for arrays and objects, but don't for Maps and Sets. The path in those cases is referring to the `Array.from()` constructions, rather than the resulting objects.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。