Skip to content

Commit 7f39737

Browse files
authored
Unrolled build for #149358
Rollup merge of #149358 - epage:fence-length, r=davidtwco fix(parse): Limit frontmatter fences to 255 dashes Like raw string literals. As discussed on #148051. Part of #136889
2 parents 2fb8053 + 70b6d77 commit 7f39737

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

compiler/rustc_parse/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ parse_frontmatter_invalid_opening_preceding_whitespace = invalid preceding white
347347
parse_frontmatter_length_mismatch = frontmatter close does not match the opening
348348
.label_opening = the opening here has {$len_opening} dashes...
349349
.label_close = ...while the close has {$len_close} dashes
350+
parse_frontmatter_too_many_dashes = too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found {$len_opening}
350351
parse_frontmatter_unclosed = unclosed frontmatter
351352
.note = frontmatter opening here was not closed
352353

compiler/rustc_parse/src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,12 @@ pub(crate) struct FrontmatterLengthMismatch {
822822
pub len_close: usize,
823823
}
824824

825+
#[derive(Diagnostic)]
826+
#[diag(parse_frontmatter_too_many_dashes)]
827+
pub(crate) struct FrontmatterTooManyDashes {
828+
pub len_opening: usize,
829+
}
830+
825831
#[derive(Diagnostic)]
826832
#[diag(parse_leading_plus_not_supported)]
827833
pub(crate) struct LeadingPlusNotSupported {

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,11 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
665665
});
666666
}
667667

668+
// Only up to 255 `-`s are allowed in code fences
669+
if u8::try_from(len_opening).is_err() {
670+
self.dcx().emit_err(errors::FrontmatterTooManyDashes { len_opening });
671+
}
672+
668673
if !rest.trim_matches(is_horizontal_whitespace).is_empty() {
669674
let span = self.mk_sp(last_line_start_pos, self.pos);
670675
self.dcx().emit_err(errors::FrontmatterExtraCharactersAfterClose { span });
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2+
//~? ERROR: too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols
3+
// ignore-tidy-linelength
4+
[dependencies]
5+
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6+
7+
#![feature(frontmatter)]
8+
9+
// check that we limit fence lengths
10+
11+
fn main() {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found 256
2+
3+
error: aborting due to 1 previous error
4+

0 commit comments

Comments
 (0)