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

Commit

Permalink
Merge pull request #1214 from 117/master
Browse files Browse the repository at this point in the history
Add numeric username support for SSH urls.
  • Loading branch information
mcuadros authored Aug 31, 2019
2 parents 3e42b8c + 4c43218 commit 8d20cc5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions internal/url/url_test.go
Original file line number Diff line number Diff line change
@@ -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{
"[email protected]:james/bond",
"[email protected]:007/bond",
"[email protected]:22:james/bond",
"[email protected]:22:007/bond",
}

for _, url := range examples {
c.Check(MatchesScpLike(url), Equals, true)
}
}

func (s *URLSuite) TestFindScpLikeComponents(c *C) {
url := "[email protected]: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 = "[email protected]: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 = "[email protected]: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 = "[email protected]: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")
}

0 comments on commit 8d20cc5

Please sign in to comment.