Skip to content

Commit 8d83b06

Browse files
committed
refactor(toml): Preserve the full newline for shebang
The shebang is thrown away so this has no end-user impact
1 parent d17d89b commit 8d83b06

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/cargo/util/toml/embedded.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,12 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
216216
}
217217

218218
// No other choice than to consider this a shebang.
219-
let (shebang, content) = source
219+
let newline_end = source
220220
.content
221-
.split_once('\n')
222-
.unwrap_or((source.content, ""));
221+
.find('\n')
222+
.map(|pos| pos + 1)
223+
.unwrap_or(source.content.len());
224+
let (shebang, content) = source.content.split_at(newline_end);
223225
source.shebang = Some(shebang);
224226
source.content = content;
225227
}
@@ -401,7 +403,7 @@ fn main() {}
401403
Ok(
402404
Source {
403405
shebang: Some(
404-
"#!/usr/bin/env cargo",
406+
"#!/usr/bin/env cargo\n",
405407
),
406408
info: None,
407409
frontmatter: Some(
@@ -427,7 +429,7 @@ Ok(
427429
Ok(
428430
Source {
429431
shebang: Some(
430-
"#!/usr/bin/env cargo\r",
432+
"#!/usr/bin/env cargo\r\n",
431433
),
432434
info: Some(
433435
"",
@@ -466,7 +468,7 @@ fn main() {}
466468
Ok(
467469
Source {
468470
shebang: Some(
469-
"#!/usr/bin/env cargo",
471+
"#!/usr/bin/env cargo\n",
470472
),
471473
info: None,
472474
frontmatter: None,
@@ -524,7 +526,7 @@ fn main() {}"#
524526
Ok(
525527
Source {
526528
shebang: Some(
527-
"#!/usr/bin/env cargo",
529+
"#!/usr/bin/env cargo\n",
528530
),
529531
info: None,
530532
frontmatter: Some(

0 commit comments

Comments
 (0)