Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default line_width does not reflect the libyaml default of 80 #257

Open
glebm opened this issue Nov 14, 2015 · 0 comments
Open

Default line_width does not reflect the libyaml default of 80 #257

glebm opened this issue Nov 14, 2015 · 0 comments

Comments

@glebm
Copy link
Contributor

glebm commented Nov 14, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant