Fix implementation and tests for cannot-be-a-base-url canonicalization
authordebris <marek.kotewicz@gmail.com>
Fri, 11 Aug 2017 15:39:18 +0000 (17:39 +0200)
committerdebris <marek.kotewicz@gmail.com>
Fri, 11 Aug 2017 15:39:18 +0000 (17:39 +0200)
src/cargo/sources/git/source.rs
tests/install.rs

index ed156af83b17eaccbb03d54c6a61c8baa184b12d..6a5154b2e6d03788723bae1bd42aa83d8a05aedf 100644 (file)
@@ -76,13 +76,10 @@ fn ident(url: &Url) -> CargoResult<String> {
 pub fn canonicalize_url(url: &Url) -> CargoResult<Url> {
     let mut url = url.clone();
 
+    // cannot-be-a-base-urls are not supported 
+    // eg. github.com:rust-lang-nursery/rustfmt.git
     if url.cannot_be_a_base() {
-        if url.scheme() != "github.com" {
-            return Err(format!("invalid url `{}`: cannot-be-a-base-URLs are not supported", url).into());
-        }
-        // it's most likely an attempt to fetch github repo
-        // https://github.com/rust-lang/cargo/issues/4394
-        url = Url::parse(&format!("https://github.com/{}", url.path())).unwrap();
+        return Err(format!("invalid url `{}`: cannot-be-a-base-URLs are not supported", url).into());
     }
 
     // Strip a trailing slash
@@ -245,22 +242,15 @@ mod test {
     }
 
     #[test]
-    fn test_canonicalize_idents_different_protocls() {
+    fn test_canonicalize_idents_different_protocols() {
         let ident1 = ident(&url("https://github.com/PistonDevelopers/piston")).unwrap();
         let ident2 = ident(&url("git://github.com/PistonDevelopers/piston")).unwrap();
         assert_eq!(ident1, ident2);
     }
 
     #[test]
-    fn test_canonicalize_github_not_a_base_urls() {
-        let ident1 = ident(&url("github.com:PistonDevelopers/piston")).unwrap();
-        let ident2 = ident(&url("https://github.com/PistonDevelopers/piston")).unwrap();
-        assert_eq!(ident1, ident2);
-    }
-
-    #[test]
-    fn test_canonicalize_not_a_base_urls() {
-        assert!(ident(&url("github.com:PistonDevelopers/piston")).is_ok());
+    fn test_canonicalize_cannot_be_a_base_urls() {
+        assert!(ident(&url("github.com:PistonDevelopers/piston")).is_err());
         assert!(ident(&url("google.com:PistonDevelopers/piston")).is_err());
     }
 
index 9d385551b73e891157bf927e2e115fe71f75cb43..5527f1628efed6d1107eb3320b3e11a5e7aa18ec 100644 (file)
@@ -902,3 +902,11 @@ historically Cargo treated this as a semver version requirement accidentally
 and will continue to do so, but this behavior will be removed eventually
 "));
 }
+
+#[test]
+fn test_install_git_cannot_be_a_base_url() {
+    assert_that(cargo_process("install").arg("--git").arg("github.com:rust-lang-nursery/rustfmt.git"),
+                execs().with_status(101).with_stderr("\
+error: invalid url `github.com:rust-lang-nursery/rustfmt.git`: cannot-be-a-base-URLs are not supported
+"));
+}