Skip to content

Commit

Permalink
Fixes #1079
Browse files Browse the repository at this point in the history
  - NewRepo() encodes clone URLs that contain spaces
  • Loading branch information
mcdafydd committed Jul 30, 2020
1 parent 0a1482d commit 0aea14a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions server/events/models/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]/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:[email protected]/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
Expand Down

0 comments on commit 0aea14a

Please sign in to comment.