Skip to content

Commit

Permalink
fix: reject leading ., ) without prefix as item marker
Browse files Browse the repository at this point in the history
  • Loading branch information
xxchan committed Jul 17, 2023
1 parent d698bf4 commit e5f79dc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ impl ItemizedBlock {
/// 1868. He wes buried in...
/// ```
fn get_marker_length(trimmed: &str) -> Option<usize> {
tracing::debug!("get_marker_length: {}", trimmed);
// https://spec.commonmark.org/0.30/#bullet-list-marker or
// https://spec.commonmark.org/0.30/#block-quote-marker
let itemized_start = ["* ", "- ", "> ", "+ "];
Expand All @@ -484,7 +485,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());
}
}
Expand Down Expand Up @@ -2142,6 +2145,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

0 comments on commit e5f79dc

Please sign in to comment.