Roundtrip not possible when using identical array twice
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia riproducendo l'esempio YAML.load(YAML.dump({ a: a, b: a })) e ispeziona i percorsi di YAML.load, YAML.dump e della gestione degli alias in Psych. L'issue non indica file o test e non definisce se debbano cambiare il dumping o il caricamento; pertanto, i criteri di accettazione devono essere stabiliti prima dell'implementazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
tl;dr:
require "yaml"
a = [1,2,3]
YAML.load(YAML.dump({ a: a, b: a }))
# raises 'Psych::Visitors::NoAliasRuby#visit_Psych_Nodes_Alias': Alias parsing was not enabled. To enable it, pass `aliases: true` to `Psych::load` or `Psych::safe_load`. (Psych::AliasesNotEnabled)
Long form
Hey there, today I noticed an error that surprised me quite a lot. Essentially as soon as you include the same array twice in a structure that you dump through Psych, it will not be loadable using a default YAML.load. You'd have to pass specific options to make it loadable.
The problem is that dump will generate YAML in the form:
---
:a: &1
- 1
- 2
- 3
:b: *1
This preserves the array identity for the hashes stored under a and b.
That's surprising to me. I'd have expected that if load disables certain YAML features by default, that dump would also only use those on an opt-in basis. Even worse: I don't see a setting documented that would allow me to disable the alias creation. The two fixes available to me right now:
- enable alias deserialization (which I believed to be disabled by default for security considerations; though I fail to find a source for that now)
- duplicate values in my
dumpinput to avoid alias generation
Second solution shown in code:
YAML.load(YAML.dump({ a: a, b: a.dup }))
=> {a: [1, 2, 3], b: [1, 2, 3]}
- Lingua principale
- Ruby
- Stelle
- 597
- Fork
- 223
- Merge medio
- 11h 23m
- PR unite (30g)
- 3
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ruby/psych
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
TheOdinProject/curriculum#31417 · 2 commenti ·
-
Allow faraday-http-cache 3.x Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
glossarist/glossarist-ruby#238 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
palladius/rails8-app-on-gcp#145 ·