Skip to content

Commit

Permalink
Trim scheme and path ( and username:password ) from args
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Nov 29, 2022
1 parent c04334e commit 8492f4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cert.go
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -77,6 +78,14 @@ func SetUserTempl(templ string) error {
const defaultPort = "443"

func SplitHostPort(hostport string) (string, string, error) {
if strings.Contains(hostport, "://") {
u, err := url.Parse(hostport)
if err != nil {
return "", "", err
}
fmt.Printf("u.Host: %s\n", u.Host)
hostport = u.Host
}
if !strings.Contains(hostport, ":") {
return hostport, defaultPort, nil
}
Expand Down
2 changes: 2 additions & 0 deletions cert_test.go
Expand Up @@ -74,6 +74,8 @@ func TestSplitHostPort(t *testing.T) {
{"smtp.example.com:465", want{"smtp.example.com", "465", ""}},
{"example.com:", want{"example.com", defaultPort, ""}},
{"example.com::", want{"", "", "address example.com::: too many colons in address"}},
{"https://example.com", want{"example.com", defaultPort, ""}},
{"https://example.com/path/to", want{"example.com", defaultPort, ""}},
}

for _, test := range tests {
Expand Down

0 comments on commit 8492f4a

Please sign in to comment.