From 03d752d293cdcf7a900d1281246f6e39a20fecbe Mon Sep 17 00:00:00 2001 From: xxchan Date: Mon, 17 Jul 2023 12:48:05 +0200 Subject: [PATCH 1/4] fix: reject leading `.`, `)` without prefix as item marker fix #5835 --- src/comment.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/comment.rs b/src/comment.rs index a000d110daa..95508bc9bdb 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -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)) { + if (1..=2).contains(&prefix.len()) + && prefix.chars().all(|c| char::is_ascii_digit(&c)) + { return Some(prefix.len() + suffix.len()); } } @@ -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); From a90095a26487af1fc2941e73d0b005091bdddeee Mon Sep 17 00:00:00 2001 From: xxchan Date: Fri, 25 Aug 2023 18:05:48 +0800 Subject: [PATCH 2/4] resolve comment --- src/comment.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/comment.rs b/src/comment.rs index 95508bc9bdb..dec925e14c0 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -482,9 +482,9 @@ impl ItemizedBlock { // allowed. for suffix in [". ", ") "] { if let Some((prefix, _)) = trimmed.split_once(suffix) { - if (1..=2).contains(&prefix.len()) - && 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()); } } From 0576b480ebfc0a61c3bed049c27c40886084956c Mon Sep 17 00:00:00 2001 From: xxchan Date: Sat, 26 Aug 2023 00:08:21 +0800 Subject: [PATCH 3/4] add a regression test --- tests/source/issue-5835.rs | 3 +++ tests/target/issue-5835.rs | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 tests/source/issue-5835.rs create mode 100644 tests/target/issue-5835.rs diff --git a/tests/source/issue-5835.rs b/tests/source/issue-5835.rs new file mode 100644 index 00000000000..c56c26915ba --- /dev/null +++ b/tests/source/issue-5835.rs @@ -0,0 +1,3 @@ +pub fn main() { + // . a +} diff --git a/tests/target/issue-5835.rs b/tests/target/issue-5835.rs new file mode 100644 index 00000000000..c56c26915ba --- /dev/null +++ b/tests/target/issue-5835.rs @@ -0,0 +1,3 @@ +pub fn main() { + // . a +} From 9a8cc7e2beb860540a612f36a5fadc9a7ac6ff91 Mon Sep 17 00:00:00 2001 From: xxchan Date: Sat, 26 Aug 2023 02:26:19 +0800 Subject: [PATCH 4/4] resolve comments --- tests/source/issue-5835.rs | 5 +++++ tests/target/issue-5835.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/source/issue-5835.rs b/tests/source/issue-5835.rs index c56c26915ba..3e4da3492ce 100644 --- a/tests/source/issue-5835.rs +++ b/tests/source/issue-5835.rs @@ -1,3 +1,8 @@ +// rustfmt-wrap_comments: true + +/// . a +pub fn foo() {} + pub fn main() { // . a } diff --git a/tests/target/issue-5835.rs b/tests/target/issue-5835.rs index c56c26915ba..3e4da3492ce 100644 --- a/tests/target/issue-5835.rs +++ b/tests/target/issue-5835.rs @@ -1,3 +1,8 @@ +// rustfmt-wrap_comments: true + +/// . a +pub fn foo() {} + pub fn main() { // . a }