test: Add test for ErrorHandler empty URL path normalization
Covers the fix for issue #334 where empty path is normalized to '/'. Coverage: 87.5% to 91.7%.
This commit is contained in:
parent
d69b0bbc86
commit
a5369ba2cd
1 changed files with 19 additions and 0 deletions
|
|
@ -441,3 +441,22 @@ func TestResponseWriter_EdgeCases(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestErrorHandler_EmptyPath(t *testing.T) {
|
||||
// Test that empty path is normalized to "/" (fix for issue #334)
|
||||
var capturedPath string
|
||||
handler := ErrorHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
capturedPath = r.URL.Path
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "http://example.com", nil)
|
||||
req.URL.Path = "" // explicitly set empty path
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
handler.ServeHTTP(rec, req)
|
||||
|
||||
if capturedPath != "/" {
|
||||
t.Errorf("expected empty path to be normalized to '/', got %q", capturedPath)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue