Default line_width does not reflect the libyaml default of 80

Aperta
#257 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
c, ruby
Ambito
backend

Direzione di ricerca

Inizia in lib/psych/visitors/yaml_tree.rb, nella selezione dello stile del nodo, e confronta la gestione della larghezza di riga con il valore predefinito di libyaml descritto in ext/psych/yaml/emitter.c. Verifica che il dumping senza un line_width esplicito si comporti allo stesso modo del dumping con line_width: 80, incluso l'esempio di stile ripiegato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

This causes the folded style to not apply unless line_width: is passed explicitly:

> s = 'asjfal sf;lkasfj;aslkfaj slfkasfkajf a;slkfjaslkfaslkfj aslkfjaslkf asklfj askl fjaklsfj aslkfjaslfjaslkfjlkffjsa'
> Psych.dump(s, line_width: 80) == Psych.dump(s)
 => false
> puts Psych.dump(s, line_width: 80)
--- >-
  asjfal sf;lkasfj;aslkfaj slfkasfkajf a;slkfjaslkfaslkfj aslkfjaslkf asklfj askl
  fjaklsfj aslkfjaslfjaslkfjlkffjsa
> puts Psych.dump(s)
--- asjfal sf;lkasfj;aslkfaj slfkasfkajf a;slkfjaslkfaslkfj aslkfjaslkf asklfj askl
  fjaklsfj aslkfjaslfjaslkfjlkffjsa
...

The libyaml default of 80 happens as follows:

First, the emitter best_width is set to 0 on initialization here:

memset(emitter, 0, sizeof(yaml_emitter_t));

It is then set to 80 in yaml_emitter_emit_stream_start here:

if (emitter->best_width >= 0
        && emitter->best_width <= emitter->best_indent*2) {
    emitter->best_width = 80;
}

On the Ruby side, we pass the options including :line_width into the emitter, but the code that picks the node style does not account for the libyaml defaults:

elsif @line_width && o.length > @line_width
    style = Nodes::Scalar::FOLDED

We should probably also default to 80 in yaml_tree.rb for uniform handling.

Lingua principale
Ruby
Stelle
596
Fork
228
Merge medio
24m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/psych

Tutte le issue di ruby/psych

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.