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

fix: reject leading ., ) without prefix as item marker #5839

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ impl ItemizedBlock {
// allowed.
for suffix in [". ", ") "] {
if let Some((prefix, _)) = trimmed.split_once(suffix) {
if prefix.len() <= 2 && prefix.chars().all(|c| char::is_ascii_digit(&c)) {
let has_leading_digits = (1..=2).contains(&prefix.len())
&& prefix.chars().all(|c| char::is_ascii_digit(&c));
if has_leading_digits {
return Some(prefix.len() + suffix.len());
}
}
Expand Down Expand Up @@ -2126,6 +2128,9 @@ fn main() {
// https://spec.commonmark.org/0.30 says: "A start number may not be negative":
"-1. Not a list item.",
"-1 Not a list item.",
// Marker without prefix are not recognized as item markers:
". Not a list item.",
") Not a list item.",
];
for line in test_inputs.iter() {
let maybe_block = ItemizedBlock::new(line);
Expand Down
8 changes: 8 additions & 0 deletions tests/source/issue-5835.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// rustfmt-wrap_comments: true

/// . a
pub fn foo() {}

pub fn main() {
// . a
}
8 changes: 8 additions & 0 deletions tests/target/issue-5835.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// rustfmt-wrap_comments: true

/// . a
pub fn foo() {}

pub fn main() {
// . a
}
Loading