Skip to content

Commit

Permalink
Fix parsing of ssh userinfo (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
seachicken authored Sep 9, 2023
1 parent ef9790c commit e130577
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion shared/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type (
}
)

var regex = regexp.MustCompile(`^(?:\w+://|\w+@)?([a-zA-Z0-9\.-]+)[:/](.+?/.+?)(?:\.git|)$`)
// https://datatracker.ietf.org/doc/html/rfc3986#section-2.3
var regex = regexp.MustCompile(`^(?:(?:[a-zA-Z0-9-._~]+)(?:://|@))?([a-zA-Z0-9-._~]+)[:/](.+?/.+?)(?:\.git|)$`)

func NewRemote(remoteConfig string) Remote {
splitConfig := strings.Fields(remoteConfig)
Expand Down
11 changes: 11 additions & 0 deletions shared/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ func Test_CreateRemoteWithScpLikeUrl(t *testing.T) {
)
}

func Test_CreateRemoteWithScpLikeUrlAndCustomUserinfo(t *testing.T) {
assert.Equal(t,
Remote{
Name: "origin",
Hostname: "github.com",
RepoName: "org/repo",
},
NewRemote("origin git0-._~@github.com:org/repo (fetch)"),
)
}

func Test_CreateRemoteWithScpLikeUrlWithoutUserinfo(t *testing.T) {
assert.Equal(t,
Remote{
Expand Down

0 comments on commit e130577

Please sign in to comment.