Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 43fe660

Browse files
authored
Merge pull request #762 from zkry/escape-basic-auth-user-pswd
plubming: transport, Escape the user and pswd for endpoint. Fixes #723
2 parents d8d17e7 + 7fd7090 commit 43fe660

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

plumbing/transport/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ func (u *Endpoint) String() string {
128128
buf.WriteString("//")
129129

130130
if u.User != "" || u.Password != "" {
131-
buf.WriteString(u.User)
131+
buf.WriteString(url.PathEscape(u.User))
132132
if u.Password != "" {
133133
buf.WriteByte(':')
134-
buf.WriteString(u.Password)
134+
buf.WriteString(url.PathEscape(u.Password))
135135
}
136136

137137
buf.WriteByte('@')

plumbing/transport/common_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package transport
22

33
import (
4+
"net/url"
45
"testing"
56

67
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability"
@@ -153,6 +154,15 @@ func (s *SuiteCommon) TestNewEndpointFileURL(c *C) {
153154
c.Assert(e.String(), Equals, "file:///foo.git")
154155
}
155156

157+
func (s *SuiteCommon) TestValidEndpoint(c *C) {
158+
e, err := NewEndpoint("http://github.com/user/repository.git")
159+
e.User = "[email protected]"
160+
e.Password = " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
161+
url, err := url.Parse(e.String())
162+
c.Assert(err, IsNil)
163+
c.Assert(url, NotNil)
164+
}
165+
156166
func (s *SuiteCommon) TestNewEndpointInvalidURL(c *C) {
157167
e, err := NewEndpoint("http://\\")
158168
c.Assert(err, NotNil)

0 commit comments

Comments
 (0)