diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 217823c2b..3f032b4fa 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -13,6 +13,8 @@ use term::color::BLACK; use util::{GitRepo, HgRepo, CargoResult, human, ChainError, internal}; use util::Config; +use toml; + #[derive(Clone, Copy, Debug, PartialEq)] pub enum VersionControl { Git, Hg, NoVcs } @@ -149,8 +151,8 @@ fn mk(config: &Config, path: &Path, name: &str, r#"[package] name = "{}" version = "0.1.0" -authors = ["{}"] -"#, name, author).as_bytes())); +authors = [{}] +"#, name, toml::Value::String(author)).as_bytes())); try!(fs::create_dir(&path.join("src"))); diff --git a/tests/test_cargo_new.rs b/tests/test_cargo_new.rs index 6a7b82c77..c315afb2f 100644 --- a/tests/test_cargo_new.rs +++ b/tests/test_cargo_new.rs @@ -138,6 +138,20 @@ test!(finds_author_user { assert!(contents.contains(r#"authors = ["foo"]"#)); }); +test!(finds_author_user_escaped { + // Use a temp dir to make sure we don't pick up .cargo/config somewhere in + // the hierarchy + let td = TempDir::new("cargo").unwrap(); + assert_that(cargo_process("new").arg("foo").env("USER", "foo \"bar\"") + .cwd(td.path().clone()), + execs().with_status(0)); + + let toml = td.path().join("foo/Cargo.toml"); + let mut contents = String::new(); + File::open(&toml).unwrap().read_to_string(&mut contents).unwrap(); + assert!(contents.contains(r#"authors = ["foo \"bar\""]"#)); +}); + test!(finds_author_username { // Use a temp dir to make sure we don't pick up .cargo/config somewhere in // the hierarchy