fix name escaping issue in Cargo.toml (#1635) and added corresponding

test
This commit is contained in:
Roy van der Vegt "platypus 2015-05-25 16:49:10 +02:00 committed by Roy van der Vegt
parent 3090cc3151
commit 284c0ef974
2 changed files with 18 additions and 2 deletions

View file

@ -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")));

View file

@ -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