Skip to content
Snippets Groups Projects
Commit 7eebc19a authored by Tamer Tas's avatar Tamer Tas
Browse files

Ensure URL calculation is portable (i.e. windows path separator bug)

Fixes #36
parent 0b64b1c1
No related branches found
No related tags found
No related merge requests found
package host package host
import ( import (
"path/filepath"
"regexp" "regexp"
"strings" "strings"
) )
const githubStorageURL = "https://codeload.github.com"
// ZipURL returns the URL of the zip archive given a github repository URL. // 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" var version = "master"
url = strings.TrimSuffix(strings.TrimPrefix(url, "/"), "/") repo = strings.TrimSuffix(strings.TrimPrefix(repo, "/"), "/")
zipRegex, _ := regexp.Compile(`zip/(\S+)$`) zipRegex, _ := regexp.Compile(`zip/(\S+)$`)
if zipRegex.MatchString(url) { if zipRegex.MatchString(repo) {
return url return repo
} }
// So this could identify a port number, but since we only support github // 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 // I don't believe using it as a version modifier is a problem. Though
// perhaps we should use something else instead? // perhaps we should use something else instead?
if strings.Contains(url, ":") { if strings.Contains(repo, ":") {
parts := strings.SplitAfter(url, ":") parts := strings.SplitAfter(repo, ":")
url = parts[0] repo = parts[0]
version = parts[1] 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, "/")
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment