Skip to content

Commit 019b357

Browse files
authored
Classify GITHUB_HOST case insensitively
Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
1 parent e3809fe commit 019b357

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎pkg/utils/api.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,12 @@ const (
301301
)
302302

303303
func classifyHost(u *url.URL) HostType {
304+
// Hostnames are case-insensitive, so "https://GitHub.com" is still github.com.
305+
hostname := strings.ToLower(u.Hostname())
304306
switch {
305-
case u.Hostname() == "github.com" || strings.HasSuffix(u.Hostname(), ".github.com"):
307+
case hostname == "github.com" || strings.HasSuffix(hostname, ".github.com"):
306308
return HostTypeDotcom
307-
case u.Hostname() == "ghe.com" || strings.HasSuffix(u.Hostname(), ".ghe.com"):
309+
case hostname == "ghe.com" || strings.HasSuffix(hostname, ".ghe.com"):
308310
return HostTypeGHEC
309311
default:
310312
return HostTypeGHES

‎pkg/utils/api_test.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ func TestParseAPIHost(t *testing.T) {
5555
input: "https://myghe.com",
5656
wantRestURL: "https://myghe.com/api/v3/",
5757
},
58+
{
59+
name: "mixed case github.com hostname",
60+
input: "https://GitHub.com",
61+
wantRestURL: "https://api.github.com/",
62+
},
63+
{
64+
name: "mixed case ghe.com subdomain",
65+
input: "https://Contoso.GHE.com",
66+
wantRestURL: "https://api.Contoso.GHE.com/",
67+
},
5868
{
5969
name: "missing scheme",
6070
input: "github.com",

0 commit comments

Comments
 (0)