- NewRepo() encodes clone URLs that contain spaces
This commit is contained in:
David McPike
2020-07-29 23:58:15 -05:00
parent 0a1482d805
commit 0aea14a8ec
2 changed files with 14 additions and 0 deletions

View File

@@ -97,6 +97,7 @@ func NewRepo(vcsHostType VCSHostType, repoFullName string, cloneURL string, vcsU
// We url encode because we're using them in a URL and weird characters can
// mess up git.
cloneURL = strings.Replace(cloneURL, " ", "%20", -1)
escapedVCSUser := url.QueryEscape(vcsUser)
escapedVCSToken := url.QueryEscape(vcsToken)
auth := fmt.Sprintf("%s:%s@", escapedVCSUser, escapedVCSToken)

View File

@@ -66,6 +66,19 @@ func TestNewRepo_CloneURLBitbucketServer(t *testing.T) {
}, repo)
}
// If the clone URL contains a space, NewRepo() should encode it
func TestNewRepo_CloneURLContainsSpace(t *testing.T) {
repo, err := models.NewRepo(models.AzureDevops, "owner/project space/repo", "https://dev.azure.com/owner/project space/repo", "u", "p")
Ok(t, err)
Equals(t, repo.CloneURL, "https://u:p@dev.azure.com/owner/project%20space/repo")
Equals(t, repo.SanitizedCloneURL, "https://u:<redacted>@dev.azure.com/owner/project%20space/repo")
repo, err = models.NewRepo(models.BitbucketCloud, "owner/repo space", "https://bitbucket.org/owner/repo space", "u", "p")
Ok(t, err)
Equals(t, repo.CloneURL, "https://u:p@bitbucket.org/owner/repo%20space.git")
Equals(t, repo.SanitizedCloneURL, "https://u:<redacted>@bitbucket.org/owner/repo%20space.git")
}
func TestNewRepo_FullNameWrongFormat(t *testing.T) {
cases := []struct {
repoFullName string