Rollup merge of #149358 - epage:fence-length, r=davidtwco
fix(parse): Limit frontmatter fences to 255 dashes Like raw string literals. As discussed on rust-lang/rust#148051. Part of rust-lang/rust#136889
This commit is contained in:
commit
af631a5396
5 changed files with 27 additions and 0 deletions
|
|
@ -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 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
|
|||
});
|
||||
}
|
||||
|
||||
// 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 });
|
||||
|
|
|
|||
11
tests/ui/frontmatter/fence-too-many-dashes.rs
Normal file
11
tests/ui/frontmatter/fence-too-many-dashes.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//~? ERROR: too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols
|
||||
// ignore-tidy-linelength
|
||||
[dependencies]
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#![feature(frontmatter)]
|
||||
|
||||
// check that we limit fence lengths
|
||||
|
||||
fn main() {}
|
||||
4
tests/ui/frontmatter/fence-too-many-dashes.stderr
Normal file
4
tests/ui/frontmatter/fence-too-many-dashes.stderr
Normal file
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue