diff --git a/src/cargo/util/frontmatter.rs b/src/cargo/util/frontmatter.rs index 41a77d576..009fd3726 100644 --- a/src/cargo/util/frontmatter.rs +++ b/src/cargo/util/frontmatter.rs @@ -95,6 +95,19 @@ impl<'s> ScriptSource<'s> { // Ends with a line that starts with a matching number of `-` only followed by whitespace let nl_fence_pattern = format!("\n{fence_pattern}"); let Some(frontmatter_nl) = input.find_slice(nl_fence_pattern.as_str()) else { + for len in (2..(nl_fence_pattern.len() - 1)).rev() { + let Some(frontmatter_nl) = input.find_slice(&nl_fence_pattern[0..len]) else { + continue; + }; + let _ = input.next_slice(frontmatter_nl.start + 1); + let close_start = input.current_token_start(); + let _ = input.next_slice(len); + let close_end = input.current_token_start(); + return Err(FrontmatterError::new( + format!("closing code fence has too few `-`"), + close_start..close_end, + )); + } return Err(FrontmatterError::new( format!("no closing `{fence_pattern}` found for frontmatter"), open_start..open_end, diff --git a/tests/testsuite/script/rustc_fixtures/mismatch-2.stderr b/tests/testsuite/script/rustc_fixtures/mismatch-2.stderr index 31743531c..48667df6a 100644 --- a/tests/testsuite/script/rustc_fixtures/mismatch-2.stderr +++ b/tests/testsuite/script/rustc_fixtures/mismatch-2.stderr @@ -1,5 +1,5 @@ -[ERROR] no closing `----` found for frontmatter - --> script:1:1 +[ERROR] closing code fence has too few `-` + --> script:3:1 | -1 | ----cargo - | ^^^^ +3 | ---cargo + | ^^^