From 6e14c200f3ace8ccff1894be3d34d6573d5a01f2 Mon Sep 17 00:00:00 2001 From: Luke Kysow Date: Wed, 25 Jul 2018 14:49:47 +0200 Subject: [PATCH] URL encode auth to avoid url issues. --- server/events/models/models.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/events/models/models.go b/server/events/models/models.go index 99c090cfb..668f26da3 100644 --- a/server/events/models/models.go +++ b/server/events/models/models.go @@ -79,9 +79,14 @@ func NewRepo(vcsHostType VCSHostType, repoFullName string, cloneURL string, vcsU } } - // Construct clone urls with http auth. Need to do both https and http - // because in GitLab's docs they have some http urls. - auth := fmt.Sprintf("%s:%s@", vcsUser, vcsToken) + // We url encode because we're using them in a URL and weird characters can + // mess up git. + escapedVCSUser := url.QueryEscape(vcsUser) + escapedVCSToken := url.QueryEscape(vcsToken) + auth := fmt.Sprintf("%s:%s@", escapedVCSUser, escapedVCSToken) + + // Construct clone urls with http and https auth. Need to do both + // because Bitbucket supports http. authedCloneURL := strings.Replace(cloneURL, "https://", "https://"+auth, -1) authedCloneURL = strings.Replace(authedCloneURL, "http://", "http://"+auth, -1)