fix(parse): Limit frontmatter fences to 255 dashes

Like raw string literals.
This commit is contained in:
Ed Page
2025-11-26 14:01:22 -06:00
parent 67094fc00a
commit 70b6d77983
5 changed files with 17 additions and 2 deletions
+1
View File
@@ -347,6 +347,7 @@ parse_frontmatter_invalid_opening_preceding_whitespace = invalid preceding white
parse_frontmatter_length_mismatch = frontmatter close does not match the opening
.label_opening = the opening here has {$len_opening} dashes...
.label_close = ...while the close has {$len_close} dashes
parse_frontmatter_too_many_dashes = too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found {$len_opening}
parse_frontmatter_unclosed = unclosed frontmatter
.note = frontmatter opening here was not closed
+6
View File
@@ -822,6 +822,12 @@ pub(crate) struct FrontmatterLengthMismatch {
pub len_close: usize,
}
#[derive(Diagnostic)]
#[diag(parse_frontmatter_too_many_dashes)]
pub(crate) struct FrontmatterTooManyDashes {
pub len_opening: usize,
}
#[derive(Diagnostic)]
#[diag(parse_leading_plus_not_supported)]
pub(crate) struct LeadingPlusNotSupported {
+5
View File
@@ -665,6 +665,11 @@ fn validate_frontmatter(
});
}
// Only up to 255 `-`s are allowed in code fences
if u8::try_from(len_opening).is_err() {
self.dcx().emit_err(errors::FrontmatterTooManyDashes { len_opening });
}
if !rest.trim_matches(is_horizontal_whitespace).is_empty() {
let span = self.mk_sp(last_line_start_pos, self.pos);
self.dcx().emit_err(errors::FrontmatterExtraCharactersAfterClose { span });
@@ -1,12 +1,11 @@
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//~? ERROR: too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols
// ignore-tidy-linelength
[dependencies]
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#![feature(frontmatter)]
//@ check-pass
// check that we limit fence lengths
fn main() {}
@@ -0,0 +1,4 @@
error: too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found 256
error: aborting due to 1 previous error