Skip to content

Commit 8d20cc5

Browse files
authored
Merge pull request go-git#1214 from 117/master
Add numeric username support for SSH urls.
2 parents 3e42b8c + 4c43218 commit 8d20cc5

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

internal/url/url.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
var (
88
isSchemeRegExp = regexp.MustCompile(`^[^:]+://`)
9-
scpLikeUrlRegExp = regexp.MustCompile(`^(?:(?P<user>[^@]+)@)?(?P<host>[^:\s]+):(?:(?P<port>[0-9]{1,5})/)?(?P<path>[^\\].*)$`)
9+
scpLikeUrlRegExp = regexp.MustCompile(`^(?:(?P<user>[^@]+)@)?(?P<host>[^:\s]+):(?:(?P<port>[0-9]{1,5})(?:\/|:))?(?P<path>[^\\].*\/[^\\].*)$`)
1010
)
1111

1212
// MatchesScheme returns true if the given string matches a URL-like

internal/url/url_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package url
2+
3+
import (
4+
"testing"
5+
6+
. "gopkg.in/check.v1"
7+
)
8+
9+
func Test(t *testing.T) { TestingT(t) }
10+
11+
type URLSuite struct{}
12+
13+
var _ = Suite(&URLSuite{})
14+
15+
func (s *URLSuite) TestMatchesScpLike(c *C) {
16+
examples := []string{
17+
"[email protected]:james/bond",
18+
"[email protected]:007/bond",
19+
"[email protected]:22:james/bond",
20+
"[email protected]:22:007/bond",
21+
}
22+
23+
for _, url := range examples {
24+
c.Check(MatchesScpLike(url), Equals, true)
25+
}
26+
}
27+
28+
func (s *URLSuite) TestFindScpLikeComponents(c *C) {
29+
url := "[email protected]:james/bond"
30+
user, host, port, path := FindScpLikeComponents(url)
31+
32+
c.Check(user, Equals, "git")
33+
c.Check(host, Equals, "github.com")
34+
c.Check(port, Equals, "")
35+
c.Check(path, Equals, "james/bond")
36+
37+
url = "[email protected]:007/bond"
38+
user, host, port, path = FindScpLikeComponents(url)
39+
40+
c.Check(user, Equals, "git")
41+
c.Check(host, Equals, "github.com")
42+
c.Check(port, Equals, "")
43+
c.Check(path, Equals, "007/bond")
44+
45+
url = "[email protected]:22:james/bond"
46+
user, host, port, path = FindScpLikeComponents(url)
47+
48+
c.Check(user, Equals, "git")
49+
c.Check(host, Equals, "github.com")
50+
c.Check(port, Equals, "22")
51+
c.Check(path, Equals, "james/bond")
52+
53+
url = "[email protected]:22:007/bond"
54+
user, host, port, path = FindScpLikeComponents(url)
55+
56+
c.Check(user, Equals, "git")
57+
c.Check(host, Equals, "github.com")
58+
c.Check(port, Equals, "22")
59+
c.Check(path, Equals, "007/bond")
60+
}

0 commit comments

Comments
 (0)