Skip to content

Commit afae9f3

Browse files
committed
Don't panic because of invalid source
1 parent 29a2165 commit afae9f3

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/cargo/core/source.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl SourceId {
131131
pub fn from_url(string: &str) -> CargoResult<SourceId> {
132132
let mut parts = string.splitn(2, '+');
133133
let kind = parts.next().unwrap();
134-
let url = parts.next().unwrap();
134+
let url = try!(parts.next().ok_or(human(format!("invalid source `{}`", string))));
135135

136136
match kind {
137137
"git" => {

tests/bad-config.rs

+39
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,45 @@ Caused by:
280280
"));
281281
}
282282

283+
#[test]
284+
fn bad_source_in_cargo_lock() {
285+
Package::new("foo", "0.1.0").publish();
286+
287+
let p = project("bar")
288+
.file("Cargo.toml", r#"
289+
[project]
290+
name = "bar"
291+
version = "0.0.1"
292+
authors = []
293+
294+
[dependencies]
295+
foo = "0.1.0"
296+
"#)
297+
.file("src/lib.rs", "")
298+
.file("Cargo.lock", r#"
299+
[root]
300+
name = "bar"
301+
version = "0.0.1"
302+
dependencies = [
303+
"foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
304+
]
305+
306+
[[package]]
307+
name = "foo"
308+
version = "0.1.0"
309+
source = "You shall not parse"
310+
"#);
311+
p.build();
312+
313+
assert_that(p.cargo("build").arg("--verbose"),
314+
execs().with_status(101).with_stderr("\
315+
[ERROR] failed to parse lock file at: [..]
316+
317+
Caused by:
318+
invalid source `You shall not parse` for the key `package.source`
319+
"));
320+
}
321+
283322
#[test]
284323
fn bad_git_dependency() {
285324
let foo = project("foo")

0 commit comments

Comments
 (0)