Default line_width does not reflect the libyaml default of 80

Đang mở
#257 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
c, ruby
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu trong lib/psych/visitors/yaml_tree.rb, tại phần lựa chọn kiểu node, và so sánh cách xử lý độ rộng dòng với giá trị mặc định của libyaml được mô tả trong ext/psych/yaml/emitter.c. Xác minh rằng việc dump mà không chỉ định line_width tường minh có hành vi giống như việc dump với line_width: 80, bao gồm cả ví dụ về kiểu folded.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Ruby
Star
596
Fork
228
Merge trung bình
24 phút
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ruby/psych

Tất cả issue của ruby/psych

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.