Skip to content

Commit c0fa9fd

Browse files
committed
fix(frontmatter): Restrict code fence length
Port rust-lang/rust#149358 over to Cargo
1 parent d85a9b0 commit c0fa9fd

File tree

4 files changed

+15
-43
lines changed

4 files changed

+15
-43
lines changed

src/cargo/util/frontmatter.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ impl<'s> ScriptSource<'s> {
7575
raw.len()..raw.len(),
7676
).push_visible_span(open_start..open_end));
7777
}
78+
_ if u8::try_from(fence_length).is_err() => {
79+
return Err(FrontmatterError::new(
80+
format!(
81+
"too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found {fence_length}"
82+
),
83+
open_start..open_end,
84+
));
85+
}
7886
_ => {}
7987
}
8088
source.open = Some(open_start..open_end);

tests/testsuite/script/rustc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ fn fence_mismatch_2() {
274274
#[rustfmt::skip] // code-generated
275275
fn fence_too_many_dashes() {
276276
let fixture_path = "tests/testsuite/script/rustc_fixtures/fence-too-many-dashes.rs";
277-
let assertion_path = "tests/testsuite/script/rustc_fixtures/fence-too-many-dashes.stdout";
278-
assert_success(fixture_path, assertion_path);
277+
let assertion_path = "tests/testsuite/script/rustc_fixtures/fence-too-many-dashes.stderr";
278+
assert_failure(fixture_path, assertion_path);
279279
}
280280

281281
#[cargo_test(nightly, reason = "-Zscript is unstable")]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[ERROR] too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found 256
2+
--> script:1:1
3+
|
4+
1 | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/testsuite/script/rustc_fixtures/fence-too-many-dashes.stdout

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)