Merge 29dd8be6eab666db9122f4be6942c383551cf7a5 into dcaa4296d111981ffb31ac3eba90bb63e1eb5ab9

This commit is contained in:
daixiheguu 2026-08-25 11:28:57 +00:00 committed by GitHub
commit 478d752bb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 19 additions and 16 deletions

View File

@ -25,6 +25,7 @@ import (
"github.com/stretchr/testify/require"
)
// testRequest sends a request and validates its response.
// params[0]=url example:http://127.0.0.1:8080/index (cannot be empty)
// params[1]=response status (custom compare status) default:"200 OK"
// params[2]=response body (custom compare content) default:"it worked"

View File

@ -283,7 +283,7 @@ func TestRenderPureJSON(t *testing.T) {
type xmlmap map[string]any
// Allows type H to be used with xml.Marshal
// MarshalXML allows xmlmap to be used with xml.Marshal.
func (h xmlmap) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
start.Name = xml.Name{
Space: "",
@ -331,7 +331,7 @@ b:
type fail struct{}
// Hook MarshalYAML
// MarshalYAML returns an error for YAML rendering failure tests.
func (ft *fail) MarshalYAML() (any, error) {
return nil, errors.New("fail")
}

View File

@ -220,7 +220,8 @@ func TestResponseWriterHijackAfterWrite(t *testing.T) {
}
}
// Test: WebSocket compatibility - allow hijack after WriteHeaderNow(), but block after body data.
// TestResponseWriterHijackAfterWriteHeaderNow verifies that hijacking is allowed after
// WriteHeaderNow but blocked after body data is written.
func TestResponseWriterHijackAfterWriteHeaderNow(t *testing.T) {
tests := []struct {
name string

View File

@ -51,7 +51,7 @@ func testRouteOK(method string, t *testing.T) {
assert.True(t, passedAny)
}
// TestSingleRouteOK tests that POST route is correctly invoked.
// testRouteNotOK tests that a request with the wrong method returns a not found response.
func testRouteNotOK(method string, t *testing.T) {
passed := false
router := New()
@ -65,7 +65,7 @@ func testRouteNotOK(method string, t *testing.T) {
assert.Equal(t, http.StatusNotFound, w.Code)
}
// TestSingleRouteOK tests that POST route is correctly invoked.
// testRouteNotOK2 tests that a request with the wrong method returns a method not allowed response.
func testRouteNotOK2(method string, t *testing.T) {
passed := false
router := New()
@ -273,7 +273,7 @@ func TestRouteRedirectFixedPath(t *testing.T) {
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
}
// TestContextParamsGet tests that a parameter can be parsed from the URL.
// TestRouteParamsByName tests that route parameters can be parsed by name.
func TestRouteParamsByName(t *testing.T) {
name := ""
lastName := ""
@ -305,7 +305,7 @@ func TestRouteParamsByName(t *testing.T) {
assert.Equal(t, "/is/super/great", wild)
}
// TestContextParamsGet tests that a parameter can be parsed from the URL even with extra slashes.
// TestRouteParamsByNameWithExtraSlash tests that route parameters can be parsed by name even with extra slashes.
func TestRouteParamsByNameWithExtraSlash(t *testing.T) {
name := ""
lastName := ""
@ -377,7 +377,7 @@ func TestRouteParamsNotEmpty(t *testing.T) {
assert.Equal(t, "/is/super/great", wild)
}
// TestHandleStaticFile - ensure the static file handles properly
// TestRouteStaticFile tests that a static file is served correctly.
func TestRouteStaticFile(t *testing.T) {
// SETUP file
testRoot, _ := os.Getwd()
@ -412,7 +412,7 @@ func TestRouteStaticFile(t *testing.T) {
assert.Equal(t, http.StatusOK, w3.Code)
}
// TestHandleStaticFile - ensure the static file handles properly
// TestRouteStaticFileFS tests that a static file from an http.FileSystem is served correctly.
func TestRouteStaticFileFS(t *testing.T) {
// SETUP file
testRoot, _ := os.Getwd()
@ -446,7 +446,7 @@ func TestRouteStaticFileFS(t *testing.T) {
assert.Equal(t, http.StatusOK, w3.Code)
}
// TestHandleStaticDir - ensure the root/sub dir handles properly
// TestRouteStaticListingDir tests that static directory listing is enabled when configured.
func TestRouteStaticListingDir(t *testing.T) {
router := New()
router.StaticFS("/", Dir("./", true))
@ -458,7 +458,7 @@ func TestRouteStaticListingDir(t *testing.T) {
assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type"))
}
// TestHandleHeadToDir - ensure the root/sub dir handles properly
// TestRouteStaticNoListing tests that static directory listing is disabled by default.
func TestRouteStaticNoListing(t *testing.T) {
router := New()
router.Static("/", "./")
@ -656,7 +656,7 @@ func TestRouterStaticFSFileNotFound(t *testing.T) {
})
}
// Reproduction test for the bug of issue #1805
// TestMiddlewareCalledOnceByRouterStaticFSNotFound reproduces the bug reported in issue #1805.
func TestMiddlewareCalledOnceByRouterStaticFSNotFound(t *testing.T) {
router := New()

View File

@ -107,7 +107,7 @@ type node struct {
fullPath string
}
// Increments priority of the given child and reorders if necessary
// incrementChildPrio increments the priority of the given child and reorders it if necessary.
func (n *node) incrementChildPrio(pos int) int {
cs := n.children
cs[pos].priority++
@ -683,7 +683,7 @@ func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) ([]by
return ciPath, ciPath != nil
}
// Shift bytes in array by n bytes left
// shiftNRuneBytes shifts bytes in the array n positions to the left.
func shiftNRuneBytes(rb [4]byte, n int) [4]byte {
switch n {
case 0:
@ -699,7 +699,7 @@ func shiftNRuneBytes(rb [4]byte, n int) [4]byte {
}
}
// Recursive case-insensitive lookup function used by n.findCaseInsensitivePath
// findCaseInsensitivePathRec recursively performs a case-insensitive path lookup.
func (n *node) findCaseInsensitivePathRec(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) []byte {
npLen := len(n.path)

View File

@ -160,7 +160,8 @@ func resolveAddress(addr []string) string {
}
}
// https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters
// isASCII reports whether s contains only ASCII characters.
// See https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters.
func isASCII(s string) bool {
for i := range len(s) {
if s[i] > unicode.MaxASCII {