akiomik / akiomik/mado

Document::lines does not split on a bare `\r`, which comrak counts as a line ending

Đang mở
#453 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
Rust
Star
407
Fork
12
Merge trung bình
5 giờ 45 phút
Pull request đã merge (30 ngày)
30

Mô tả

`Document::lines` splits the document with `str::lines`, which ends a line at
`\n` and nowhere else. `CommonMark` also ends one at a bare `\r`, and comrak
counts lines that way, so for a document written with `\r` alone the line numbers
the rules read and the line numbers comrak reports describe different lines.

## Reproduction

```sh
printf '# H\r\rtext \rmore\r' > cr.md
mado check cr.md
```

```
cr.md:1:1: MD047 File should end with a single newline character
```

mdl reports `cr.md:3: MD009 Trailing spaces` for the same document, and that is
the finding: line 3 ends with three spaces. mado reports MD009 nowhere and
reports MD047 instead, on a file that does end with a line ending.

The same document written with `\n` reports the MD009 and no MD047.

## Cause

`src/document.rs:45`:

```rust
let lines: Vec<_> = text.lines().map(ToOwned::to_owned).collect();
```

With `\r` alone there is no `\n` to split on, so `lines` holds one entry: the
whole document. Every rule that reads it reads that one string. MD047 asks
whether the text ends with exactly one newline and a `\r` is not one. MD009 looks
for trailing spaces at the end of each line and the document has only one,
ending in `\r`.

`Document::text` is the unsplit document and is unaffected, as is anything
working from comrak positions alone.

## Reach

`doc.lines` is read by MD007, MD009, MD010, MD012, MD013, MD027, MD030, MD035,
MD038 and MD047. Which of them report wrongly depends on what each looks for,
but none of them is reading the lines comrak numbered.

## Not urgent

A document written with `\r` alone is a classic Mac OS artefact, and nothing in
the corpora here has one. Filing it because the assumption is shared by ten
rules and is invisible at each of them: the split happens once, in
`Document::new`, and every rule inherits it.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

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.