Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
Expand Down
8 changes: 4 additions & 4 deletions cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ func extractHost(origin string) string {
}

// Find end of host (port separator or end of string)
if colonIdx := strings.IndexByte(rest, ':'); colonIdx != -1 {
return rest[:colonIdx]
if host, _, ok := strings.Cut(rest, ":"); ok {
return host
}
if slashIdx := strings.IndexByte(rest, '/'); slashIdx != -1 {
return rest[:slashIdx]
if host, _, ok := strings.Cut(rest, "/"); ok {
return host
}
return rest
}
Expand Down
10 changes: 2 additions & 8 deletions rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,9 @@ func Origins(origins ...string) Rule {
// Matching requires a dot boundary, preventing "evilexample.com" from matching "example.com".
func OriginSuffix(suffix string) Rule {
// Check for port wildcard
portWildcard := strings.HasSuffix(suffix, ":*")
if portWildcard {
suffix = suffix[:len(suffix)-2] // remove ":*"
}
suffix, portWildcard := strings.CutSuffix(suffix, ":*")

suffixOnly := strings.HasPrefix(suffix, ".")
if suffixOnly {
suffix = suffix[1:] // remove leading dot for storage
}
suffix, suffixOnly := strings.CutPrefix(suffix, ".")
return Rule{c: config{
matchType: matchSuffix,
suffix: suffix,
Expand Down