[ BUG ] --insert writes LF line endings into a file with CRLF line endings

Đang mở Phù hợp với người mới
#101 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
80/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
cli, tooling

Hướng nghiên cứu

Bắt đầu với internal/core/usecase/insertmd/markers.go và theo dõi cách replaceBetweenMarkers xử lý ký tự kết thúc dòng; issue cũng nói quy tắc tương tự áp dụng cho --stdout (#95). Tái hiện bằng đầu vào CRLF được cung cấp, sau đó kiểm tra rằng các dòng được chèn dùng CRLF khi dấu đánh dấu bắt đầu có \r ở cuối, còn các dòng khác vẫn giữ nguyên.

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

Mô tả

bug

Describe the bug

In a file with CRLF line endings, --insert finds the markers, but every line it writes
between them ends with \n only, so the file ends up with mixed line endings. The Bash
version writes these lines with \r\n when the <!--ts--> line ends with \r
(ekalinin/github-markdown-toc#119, fixed in ekalinin/github-markdown-toc#195).

To Reproduce

printf '<!--ts-->\r\n<!--te-->\r\n\r\n# Title\r\n\r\n## Section\r\n' > crlf.md
gh-md-toc --insert --no-backup crlf.md
od -c crlf.md

Actual, line by line:

<!--ts-->\r\n
* [Title](#title)\n
  * [Section](#section)\n
\n
<!-- Created by https://github.com/ekalinin/github-markdown-toc.go -->\n
<!-- Added by: <user>, at: <date> -->\n
<!--te-->\r\n
\r\n
# Title\r\n
\r\n
## Section\r\n

Expected behavior

When the <!--ts--> line ends with \r, every line written between the markers (the TOC
entries, the empty line and the footer lines) ends with \r\n. Otherwise they end with
\n, as now. All other lines are kept as they are.

Environment (please complete the following information):

  • OS: macOS (darwin/arm64)
  • Version: 2.0.1, current master (dd680f7)

Additional context

  • replaceBetweenMarkers (internal/core/usecase/insertmd/markers.go) splits the file on
    \n and joins the TOC block with \n. The marker lines already keep their \r.
  • The same rule applies to --stdout (#95).
Ngôn ngữ chính
Go
Star
525
Fork
89
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
1

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

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

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 ekalinin/github-markdown-toc.go

Tất cả issue của ekalinin/github-markdown-toc.go

Issue tương tự

Thêm issue về Go

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.