aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2019-08-31 11:57:37 +0200
committerGitHub <noreply@github.com>2019-08-31 11:57:37 +0200
commit8d20cc5916edf7cfa6a9c5ed069f0640dc823c12 (patch)
treef73892663b8bf1a9a9eb5c49e29e940e31e08ed1
parent3e42b8cd3f20dad073db846348418aa218c7d23c (diff)
parent4c43218e7b19b9db7d9ce6964a6cfc569cfddbf1 (diff)
downloadgo-git-8d20cc5916edf7cfa6a9c5ed069f0640dc823c12.tar.gz
Merge pull request #1214 from 117/master
Add numeric username support for SSH urls.
-rw-r--r--internal/url/url.go2
-rwxr-xr-xinternal/url/url_test.go60
2 files changed, 61 insertions, 1 deletions
diff --git a/internal/url/url.go b/internal/url/url.go
index 0f0d709..14cf133 100644
--- a/internal/url/url.go
+++ b/internal/url/url.go
@@ -6,7 +6,7 @@ import (
var (
isSchemeRegExp = regexp.MustCompile(`^[^:]+://`)
- scpLikeUrlRegExp = regexp.MustCompile(`^(?:(?P<user>[^@]+)@)?(?P<host>[^:\s]+):(?:(?P<port>[0-9]{1,5})/)?(?P<path>[^\\].*)$`)
+ scpLikeUrlRegExp = regexp.MustCompile(`^(?:(?P<user>[^@]+)@)?(?P<host>[^:\s]+):(?:(?P<port>[0-9]{1,5})(?:\/|:))?(?P<path>[^\\].*\/[^\\].*)$`)
)
// MatchesScheme returns true if the given string matches a URL-like
diff --git a/internal/url/url_test.go b/internal/url/url_test.go
new file mode 100755
index 0000000..d168db6
--- /dev/null
+++ b/internal/url/url_test.go
@@ -0,0 +1,60 @@
+package url
+
+import (
+ "testing"
+
+ . "gopkg.in/check.v1"
+)
+
+func Test(t *testing.T) { TestingT(t) }
+
+type URLSuite struct{}
+
+var _ = Suite(&URLSuite{})
+
+func (s *URLSuite) TestMatchesScpLike(c *C) {
+ examples := []string{
+ "git@github.com:james/bond",
+ "git@github.com:007/bond",
+ "git@github.com:22:james/bond",
+ "git@github.com:22:007/bond",
+ }
+
+ for _, url := range examples {
+ c.Check(MatchesScpLike(url), Equals, true)
+ }
+}
+
+func (s *URLSuite) TestFindScpLikeComponents(c *C) {
+ url := "git@github.com:james/bond"
+ user, host, port, path := FindScpLikeComponents(url)
+
+ c.Check(user, Equals, "git")
+ c.Check(host, Equals, "github.com")
+ c.Check(port, Equals, "")
+ c.Check(path, Equals, "james/bond")
+
+ url = "git@github.com:007/bond"
+ user, host, port, path = FindScpLikeComponents(url)
+
+ c.Check(user, Equals, "git")
+ c.Check(host, Equals, "github.com")
+ c.Check(port, Equals, "")
+ c.Check(path, Equals, "007/bond")
+
+ url = "git@github.com:22:james/bond"
+ user, host, port, path = FindScpLikeComponents(url)
+
+ c.Check(user, Equals, "git")
+ c.Check(host, Equals, "github.com")
+ c.Check(port, Equals, "22")
+ c.Check(path, Equals, "james/bond")
+
+ url = "git@github.com:22:007/bond"
+ user, host, port, path = FindScpLikeComponents(url)
+
+ c.Check(user, Equals, "git")
+ c.Check(host, Equals, "github.com")
+ c.Check(port, Equals, "22")
+ c.Check(path, Equals, "007/bond")
+}