Skip to content
Closed
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
3 changes: 3 additions & 0 deletions regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ type routeRegexp struct {

// Match matches the regexp against the URL host or path.
func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool {
if r == nil {
return false
}
if r.regexpType == regexpTypeHost {
host := getHost(req)
if r.wildcardHostPort {
Expand Down
13 changes: 13 additions & 0 deletions regexp_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package mux

import (
"net/http"
"net/url"
"reflect"
"strconv"
"strings"
"testing"
)

func Test_routeRegexp_Match_NilReceiver(t *testing.T) {
var r *routeRegexp
req, _ := http.NewRequest("GET", "http://example.com/test", nil)
match := &RouteMatch{}

// Calling Match on a nil routeRegexp should not panic and return false
result := r.Match(req, match)
if result {
t.Error("Expected Match to return false for nil receiver, got true")
}
}

func Test_newRouteRegexp_Errors(t *testing.T) {
tests := []struct {
in, out string
Expand Down
Loading