blakeembrey / blakeembrey/javascript-stringify
Repeated references in Maps & Sets produce broken output
- 主要語言
- 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.
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
從 stringifyPath 以及提供的 stringify(..., { references: true }) 重現中涉及的 Map/Set 處理開始。追蹤如何從 Array.from() 建立路徑,並驗證 eval(bad) 能夠成功執行,同時保留重複參照。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript, typescript
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100