diff --git a/internal/gatewayapi/sort.go b/internal/gatewayapi/sort.go index 00a5fc6389dd..01362c9a6d6d 100644 --- a/internal/gatewayapi/sort.go +++ b/internal/gatewayapi/sort.go @@ -18,25 +18,19 @@ func (x XdsIRRoutes) Swap(i, j int) { x[i], x[j] = x[j], x[i] } func (x XdsIRRoutes) Less(i, j int) bool { // 1. Sort based on path match type - // Exact > PathPrefix > RegularExpression + // Exact > RegularExpression > PathPrefix if x[i].PathMatch != nil && x[i].PathMatch.Exact != nil { if x[j].PathMatch != nil { - if x[j].PathMatch.Prefix != nil { - return false - } - if x[j].PathMatch.SafeRegex != nil { + if x[j].PathMatch.Prefix != nil || x[j].PathMatch.SafeRegex != nil { return false } } } if x[i].PathMatch != nil && x[i].PathMatch.Prefix != nil { if x[j].PathMatch != nil { - if x[j].PathMatch.Exact != nil { + if x[j].PathMatch.Exact != nil || x[j].PathMatch.SafeRegex != nil { return true } - if x[j].PathMatch.SafeRegex != nil { - return false - } } } if x[i].PathMatch != nil && x[i].PathMatch.SafeRegex != nil { @@ -45,7 +39,7 @@ func (x XdsIRRoutes) Less(i, j int) bool { return true } if x[j].PathMatch.Prefix != nil { - return true + return false } } } @@ -96,12 +90,12 @@ func pathMatchCount(pathMatch *ir.StringMatch) int { if pathMatch.Exact != nil { return len(*pathMatch.Exact) } - if pathMatch.Prefix != nil { - return len(*pathMatch.Prefix) - } if pathMatch.SafeRegex != nil { return len(*pathMatch.SafeRegex) } + if pathMatch.Prefix != nil { + return len(*pathMatch.Prefix) + } } return 0 }