From d685ca138f51e430888600b83c4d79cd9f967d36 Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 18 Dec 2024 19:48:07 +0100 Subject: [PATCH 1/4] Update pulldown-cmark to 0.12 --- Cargo.lock | 13 ++++++++++--- parser/Cargo.toml | 2 +- parser/src/ignore_block.rs | 10 +++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7680e03b3..fae2b04b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1738,16 +1738,23 @@ dependencies = [ [[package]] name = "pulldown-cmark" -version = "0.7.2" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca36dea94d187597e104a5c8e4b07576a8a45aa5db48a65e12940d3eb7461f55" +checksum = "f86ba2052aebccc42cbbb3ed234b8b13ce76f75c3551a303cb2bcffcff12bb14" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", "getopts", "memchr", + "pulldown-cmark-escape", "unicase", ] +[[package]] +name = "pulldown-cmark-escape" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae" + [[package]] name = "quote" version = "1.0.33" diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 22bf0aaf5..307504f13 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -5,6 +5,6 @@ authors = ["Mark Rousskov "] edition = "2021" [dependencies] -pulldown-cmark = "0.7.0" +pulldown-cmark = "0.12.0" log = "0.4" regex = "1.6.0" diff --git a/parser/src/ignore_block.rs b/parser/src/ignore_block.rs index 250273e42..f9b101bd3 100644 --- a/parser/src/ignore_block.rs +++ b/parser/src/ignore_block.rs @@ -1,4 +1,4 @@ -use pulldown_cmark::{Event, Parser, Tag}; +use pulldown_cmark::{Event, Parser, Tag, TagEnd}; use std::ops::Range; #[derive(Debug)] @@ -14,18 +14,18 @@ impl IgnoreBlocks { if let Event::Start(Tag::CodeBlock(_)) = event { let start = range.start; while let Some((event, range)) = parser.next() { - if let Event::End(Tag::CodeBlock(_)) = event { + if let Event::End(TagEnd::CodeBlock) = event { ignore.push(start..range.end); break; } } - } else if let Event::Start(Tag::BlockQuote) = event { + } else if let Event::Start(Tag::BlockQuote(_)) = event { let start = range.start; let mut count = 1; while let Some((event, range)) = parser.next() { - if let Event::Start(Tag::BlockQuote) = event { + if let Event::Start(Tag::BlockQuote(_)) = event { count += 1; - } else if let Event::End(Tag::BlockQuote) = event { + } else if let Event::End(TagEnd::BlockQuote(_)) = event { count -= 1; if count == 0 { ignore.push(start..range.end); From 43378a6f48cb64cf21cfcd4425f6389ad81e2625 Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 18 Dec 2024 20:11:26 +0100 Subject: [PATCH 2/4] Ignore inline-html --- parser/src/ignore_block.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/parser/src/ignore_block.rs b/parser/src/ignore_block.rs index f9b101bd3..2ada46819 100644 --- a/parser/src/ignore_block.rs +++ b/parser/src/ignore_block.rs @@ -33,6 +33,8 @@ impl IgnoreBlocks { } } } + } else if let Event::InlineHtml(_) = event { + ignore.push(range); } else if let Event::Code(_) = event { ignore.push(range); } @@ -92,7 +94,13 @@ fn cbs_1() { fn cbs_2() { assert_eq!( bodies("`hey you` me too"), - [Ignore::Yes("`hey you`"), Ignore::No(" me too")] + [ + Ignore::Yes("`hey you`"), + Ignore::No(" "), + Ignore::Yes(""), + Ignore::No("me too"), + Ignore::Yes("") + ] ); } @@ -100,7 +108,13 @@ fn cbs_2() { fn cbs_3() { assert_eq!( bodies(r"`hey you\` `me too"), - [Ignore::Yes(r"`hey you\`"), Ignore::No(" `me too")] + [ + Ignore::Yes("`hey you\\`"), + Ignore::No(" "), + Ignore::Yes(""), + Ignore::No("`me too"), + Ignore::Yes("") + ] ); } From 7f122c822ebee922e5547313e0cd6dacf1306097 Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 18 Dec 2024 20:40:01 +0100 Subject: [PATCH 3/4] Also ignore html block --- parser/src/ignore_block.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/parser/src/ignore_block.rs b/parser/src/ignore_block.rs index 2ada46819..627a6e69a 100644 --- a/parser/src/ignore_block.rs +++ b/parser/src/ignore_block.rs @@ -33,6 +33,14 @@ impl IgnoreBlocks { } } } + } else if let Event::Start(Tag::HtmlBlock) = event { + let start = range.start; + while let Some((event, range)) = parser.next() { + if let Event::End(TagEnd::HtmlBlock) = event { + ignore.push(start..range.end); + break; + } + } } else if let Event::InlineHtml(_) = event { ignore.push(range); } else if let Event::Code(_) = event { @@ -253,3 +261,24 @@ fn cbs_11() { ], ); } + +#[test] +fn cbs_12() { + assert_eq!( + bodies( + " +Test + + + +" + ), + [ + Ignore::No("\nTest\n\n"), + Ignore::Yes("\n"), + Ignore::Yes("\n") + ], + ); +} From fdd2173a9f2a3213a62597cd4e327fc767818ebe Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 18 Dec 2024 20:43:08 +0100 Subject: [PATCH 4/4] Make sure review commands are ignored in html blocks --- parser/src/command.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/parser/src/command.rs b/parser/src/command.rs index 2e645863e..226aa7d9f 100644 --- a/parser/src/command.rs +++ b/parser/src/command.rs @@ -350,7 +350,13 @@ fn review_errors() { #[test] fn review_ignored() { // Checks for things that shouldn't be detected. - for input in ["r", "reviewer? abc", "r foo"] { + for input in [ + "r", + "reviewer? abc", + "r foo", + "\n r? @bot\n", + "", + ] { let mut input = Input::new(input, vec!["bot"]); assert_eq!(input.next(), None); }