From 7eebc19aad3fc4dea45389493e47832fe1bf3070 Mon Sep 17 00:00:00 2001
From: Tamer Tas <contact@tmrts.com>
Date: Sat, 7 Jan 2017 16:49:52 +0200
Subject: [PATCH] Ensure URL calculation is portable (i.e. windows path
 separator bug)

Fixes #36
---
 pkg/host/github.go | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/pkg/host/github.go b/pkg/host/github.go
index 29a7a85..bc31971 100644
--- a/pkg/host/github.go
+++ b/pkg/host/github.go
@@ -1,33 +1,36 @@
 package host
 
 import (
-	"path/filepath"
 	"regexp"
 	"strings"
 )
 
+const githubStorageURL = "https://codeload.github.com"
+
 // ZipURL returns the URL of the zip archive given a github repository URL.
-func ZipURL(url string) string {
+func ZipURL(repo string) string {
 	var version = "master"
 
-	url = strings.TrimSuffix(strings.TrimPrefix(url, "/"), "/")
+	repo = strings.TrimSuffix(strings.TrimPrefix(repo, "/"), "/")
 
 	zipRegex, _ := regexp.Compile(`zip/(\S+)$`)
-	if zipRegex.MatchString(url) {
-		return url
+	if zipRegex.MatchString(repo) {
+		return repo
 	}
 
 	// So this could identify a port number, but since we only support github
 	// I don't believe using it as a version modifier is a problem. Though
 	// perhaps we should use something else instead?
-	if strings.Contains(url, ":") {
-		parts := strings.SplitAfter(url, ":")
+	if strings.Contains(repo, ":") {
+		parts := strings.SplitAfter(repo, ":")
 
-		url = parts[0]
+		repo = parts[0]
 		version = parts[1]
 
-		url = strings.TrimSuffix(url, ":")
+		repo = strings.TrimSuffix(repo, ":")
 	}
 
-	return "https://codeload.github.com/" + filepath.Join(url, "/zip/"+version)
+	urlTokens := []string{githubStorageURL, repo, "zip", version}
+
+	return strings.Join(urlTokens, "/")
 }
-- 
GitLab