Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/cargo/util/frontmatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ impl<'s> ScriptSource<'s> {
raw.len()..raw.len(),
).push_visible_span(open_start..open_end));
}
_ if u8::try_from(fence_length).is_err() => {
return Err(FrontmatterError::new(
format!(
"too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found {fence_length}"
),
open_start..open_end,
));
}
_ => {}
}
source.open = Some(open_start..open_end);
Expand Down
8 changes: 8 additions & 0 deletions tests/testsuite/script/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ fn fence_mismatch_2() {
assert_failure(fixture_path, assertion_path);
}

#[cargo_test(nightly, reason = "-Zscript is unstable")]
#[rustfmt::skip] // code-generated
fn fence_too_many_dashes() {
let fixture_path = "tests/testsuite/script/rustc_fixtures/fence-too-many-dashes.rs";
let assertion_path = "tests/testsuite/script/rustc_fixtures/fence-too-many-dashes.stderr";
assert_failure(fixture_path, assertion_path);
}

#[cargo_test(nightly, reason = "-Zscript is unstable")]
#[rustfmt::skip] // code-generated
fn fence_unclosed_1() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[dependencies]
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#![feature(frontmatter)]

// check that we limit fence lengths

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[ERROR] too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found 256
--> script:1:1
|
1 | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^