]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/go-getter/source.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / go-getter / source.go
index c63f2bbaf9e656c6d01188d0c1844ae11c803eee..dab6d400cb77cf044952e1afe2a47ac3437db61e 100644 (file)
@@ -6,18 +6,31 @@ import (
        "strings"
 )
 
-// SourceDirSubdir takes a source and returns a tuple of the URL without
-// the subdir and the URL with the subdir.
+// SourceDirSubdir takes a source URL and returns a tuple of the URL without
+// the subdir and the subdir.
+//
+// ex:
+//   dom.com/path/?q=p               => dom.com/path/?q=p, ""
+//   proto://dom.com/path//*?q=p     => proto://dom.com/path?q=p, "*"
+//   proto://dom.com/path//path2?q=p => proto://dom.com/path?q=p, "path2"
+//
 func SourceDirSubdir(src string) (string, string) {
-       // Calcaulate an offset to avoid accidentally marking the scheme
+
+       // URL might contains another url in query parameters
+       stop := len(src)
+       if idx := strings.Index(src, "?"); idx > -1 {
+               stop = idx
+       }
+
+       // Calculate an offset to avoid accidentally marking the scheme
        // as the dir.
        var offset int
-       if idx := strings.Index(src, "://"); idx > -1 {
+       if idx := strings.Index(src[:stop], "://"); idx > -1 {
                offset = idx + 3
        }
 
        // First see if we even have an explicit subdir
-       idx := strings.Index(src[offset:], "//")
+       idx := strings.Index(src[offset:stop], "//")
        if idx == -1 {
                return src, ""
        }