Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip angle brackets from author email before passing to template. #6243

Merged
merged 1 commit into from
Nov 1, 2018
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
Strip angle brackets from author email before passing to template.
Some people already have angle brackets around their email in
git settings or other author sources. Right now if you create
a new project the Cargo.toml would render something like:

authors = ["bar <<foo@baz>>"]

instead of

authors = ["bar <foo@baz>"]

This detects the emails that start and end with <> and removes them.
  • Loading branch information
btashton committed Nov 1, 2018
commit 7d579483c6141b47dd619d09908941e7b2d1416c
12 changes: 11 additions & 1 deletion src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,17 @@ fn discover_author() -> CargoResult<(String, Option<String>)> {
.or_else(|| get_environment_variable(&email_variables[3..]));

let name = name.trim().to_string();
let email = email.map(|s| s.trim().to_string());
let email = email.map(|s| {
let mut s = s.trim();

// In some cases emails will already have <> remove them since they
// are already added when needed.
if s.starts_with("<") && s.ends_with(">") {
s = &s[1..s.len() - 1];
}

s.to_string()
});

Ok((name, email))
}
Expand Down
17 changes: 17 additions & 0 deletions tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,23 @@ fn author_prefers_cargo() {
assert!(!root.join("foo/.gitignore").exists());
}

#[test]
fn strip_angle_bracket_author_email() {
create_empty_gitconfig();
cargo_process("new foo")
.env("USER", "bar")
.env("EMAIL", "<baz>")
.run();

let toml = paths::root().join("foo/Cargo.toml");
let mut contents = String::new();
File::open(&toml)
.unwrap()
.read_to_string(&mut contents)
.unwrap();
assert!(contents.contains(r#"authors = ["bar <baz>"]"#));
}

#[test]
fn git_prefers_command_line() {
let root = paths::root();
Expand Down