blakeembrey / blakeembrey/javascript-stringify
Repeated references in Maps & Sets produce broken output
- Linguagem predominante
- TypeScript
- Estrelas
- 146
- Forks
- 16
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
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.
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
Start with stringifyPath and the Map/Set handling exercised by the provided stringify(..., { references: true }) reproduction. Trace how paths are built from Array.from() and verify that eval(bad) succeeds while repeated references remain preserved.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- javascript, typescript
- Domínio
- tooling
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 45/100