From 8db3a9546b59fdd5e7203f2e63a828e3c5108e7e Mon Sep 17 00:00:00 2001 From: Geert-Jan Zwiers <34610306+GJZwiers@users.noreply.github.com> Date: Fri, 11 Mar 2022 02:14:32 +0100 Subject: fix(test): skip typechecking for blocks inside HTML comments (#13889) --- cli/tools/test.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'cli/tools/test.rs') diff --git a/cli/tools/test.rs b/cli/tools/test.rs index 74646986d..61a37c7ff 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -543,6 +543,10 @@ fn extract_files_from_regex_blocks( let files = blocks_regex .captures_iter(source) .filter_map(|block| { + if block.get(1) == None { + return None; + } + let maybe_attributes: Option> = block .get(1) .map(|attributes| attributes.as_str().split(' ').collect()); @@ -663,7 +667,12 @@ fn extract_files_from_fenced_blocks( source: &str, media_type: MediaType, ) -> Result, AnyError> { - let blocks_regex = Regex::new(r"```([^\r\n]*)\r?\n([\S\s]*?)```")?; + // The pattern matches code blocks as well as anything in HTML comment syntax, + // but it stores the latter without any capturing groups. This way, a simple + // check can be done to see if a block is inside a comment (and skip typechecking) + // or not by checking for the presence of capturing groups in the matches. + let blocks_regex = + Regex::new(r"(?s)|```([^\r\n]*)\r?\n([\S\s]*?)```")?; let lines_regex = Regex::new(r"(?:\# ?)?(.*)")?; extract_files_from_regex_blocks( -- cgit v1.2.3