Skip to content

Commit b14a5f4

Browse files
committed
fix(embedded): Don't parse indented frontmatter
1 parent a00d0ba commit b14a5f4

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/cargo/util/toml/embedded.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ impl<'s> ScriptSource<'s> {
153153
let without_spaces = rest.trim_start_matches([' ', '\t']);
154154
let without_nl = without_spaces.trim_start_matches(['\r', '\n']);
155155
if without_nl == rest {
156+
// nothing trimmed
156157
break;
158+
} else if without_nl == without_spaces {
159+
// frontmatter must come after a newline
160+
return Ok(source);
157161
}
158162
rest = without_nl;
159163
}
@@ -468,18 +472,22 @@ fn main() {}
468472

469473
#[test]
470474
fn split_indent() {
471-
assert_err(
472-
ScriptSource::parse(
473-
r#"#!/usr/bin/env cargo
475+
assert_source(
476+
r#"#!/usr/bin/env cargo
474477
---
475478
[dependencies]
476479
time="0.1.25"
477480
----
478481
479482
fn main() {}
480483
"#,
481-
),
482-
str!["unexpected trailing content on closing fence: `-`"],
484+
str![[r##"
485+
shebang: "#!/usr/bin/env cargo\n"
486+
info: None
487+
frontmatter: None
488+
content: " ---\n [dependencies]\n time=\"0.1.25\"\n ----\n\nfn main() {}\n"
489+
490+
"##]],
483491
);
484492
}
485493

0 commit comments

Comments
 (0)