aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZachary Romero <zacromero3@gmail.com>2018-02-28 22:37:42 +0300
committerZachary Romero <zacromero3@gmail.com>2018-02-28 22:37:42 +0300
commit7fd7090a73f623c74c9f26fe2fcfc8ef86131fe1 (patch)
tree33e114aa2fc4c41f8bfba724067293b551f3ccef
parent886dc83f3ed518a78772055497bcc7d7621b468e (diff)
downloadgo-git-7fd7090a73f623c74c9f26fe2fcfc8ef86131fe1.tar.gz
plubming: transport, Escape the user and password for endpoint. Fixes #723
Signed-off-by: Zachary Romero <zacromero3@gmail.com>
-rw-r--r--plumbing/transport/common.go4
-rw-r--r--plumbing/transport/common_test.go10
2 files changed, 12 insertions, 2 deletions
diff --git a/plumbing/transport/common.go b/plumbing/transport/common.go
index cc9682f..f7b882b 100644
--- a/plumbing/transport/common.go
+++ b/plumbing/transport/common.go
@@ -128,10 +128,10 @@ func (u *Endpoint) String() string {
buf.WriteString("//")
if u.User != "" || u.Password != "" {
- buf.WriteString(u.User)
+ buf.WriteString(url.PathEscape(u.User))
if u.Password != "" {
buf.WriteByte(':')
- buf.WriteString(u.Password)
+ buf.WriteString(url.PathEscape(u.Password))
}
buf.WriteByte('@')
diff --git a/plumbing/transport/common_test.go b/plumbing/transport/common_test.go
index 4203ce9..17f62a6 100644
--- a/plumbing/transport/common_test.go
+++ b/plumbing/transport/common_test.go
@@ -1,6 +1,7 @@
package transport
import (
+ "net/url"
"testing"
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability"
@@ -153,6 +154,15 @@ func (s *SuiteCommon) TestNewEndpointFileURL(c *C) {
c.Assert(e.String(), Equals, "file:///foo.git")
}
+func (s *SuiteCommon) TestValidEndpoint(c *C) {
+ e, err := NewEndpoint("http://github.com/user/repository.git")
+ e.User = "person@mail.com"
+ e.Password = " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
+ url, err := url.Parse(e.String())
+ c.Assert(err, IsNil)
+ c.Assert(url, NotNil)
+}
+
func (s *SuiteCommon) TestNewEndpointInvalidURL(c *C) {
e, err := NewEndpoint("http://\\")
c.Assert(err, NotNil)