mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
fix(parse): Limit frontmatter fences to 255 dashes
Like raw string literals.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user