blakeembrey / blakeembrey/javascript-stringify
Repeated references in Maps & Sets produce broken output
- Langage dominant
- TypeScript
- Étoiles
- 146
- Forks
- 16
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par stringifyPath et la gestion de Map/Set exercée par la reproduction fournie de stringify(..., { references: true }). Suivez la manière dont les chemins sont construits à partir de Array.from() et vérifiez que eval(bad) réussit tout en préservant les références répétées.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, typescript
- Domaine
- tooling
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100