mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-14 12:12:12 +08:00
Merge e8622bf445ffb81bf4bced0ecfeca2712710a02b into 4dec17afdff48e8018c83618fbbe69fceeb2b41d
This commit is contained in:
commit
114d472cce
18
utils.go
18
utils.go
@ -114,13 +114,6 @@ func parseAccept(acceptHeader string) []string {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func lastChar(str string) uint8 {
|
|
||||||
if str == "" {
|
|
||||||
panic("The length of the string can't be 0")
|
|
||||||
}
|
|
||||||
return str[len(str)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
func nameOfFunction(f any) string {
|
func nameOfFunction(f any) string {
|
||||||
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
|
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
|
||||||
}
|
}
|
||||||
@ -131,7 +124,7 @@ func joinPaths(absolutePath, relativePath string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
finalPath := path.Join(absolutePath, relativePath)
|
finalPath := path.Join(absolutePath, relativePath)
|
||||||
if lastChar(relativePath) == '/' && lastChar(finalPath) != '/' {
|
if strings.HasSuffix(relativePath, "/") && !strings.HasSuffix(finalPath, "/") {
|
||||||
return finalPath + "/"
|
return finalPath + "/"
|
||||||
}
|
}
|
||||||
return finalPath
|
return finalPath
|
||||||
@ -155,10 +148,7 @@ func resolveAddress(addr []string) string {
|
|||||||
|
|
||||||
// https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters
|
// https://stackoverflow.com/questions/53069040/checking-a-string-contains-only-ascii-characters
|
||||||
func isASCII(s string) bool {
|
func isASCII(s string) bool {
|
||||||
for i := 0; i < len(s); i++ {
|
return !strings.ContainsFunc(s, func(r rune) bool {
|
||||||
if s[i] > unicode.MaxASCII {
|
return r > unicode.MaxASCII
|
||||||
return false
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
@ -54,12 +54,6 @@ func TestWrap(t *testing.T) {
|
|||||||
assert.Equal(t, "hola!", w.Body.String())
|
assert.Equal(t, "hola!", w.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLastChar(t *testing.T) {
|
|
||||||
assert.Equal(t, uint8('a'), lastChar("hola"))
|
|
||||||
assert.Equal(t, uint8('s'), lastChar("adios"))
|
|
||||||
assert.Panics(t, func() { lastChar("") })
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseAccept(t *testing.T) {
|
func TestParseAccept(t *testing.T) {
|
||||||
parts := parseAccept("text/html , application/xhtml+xml,application/xml;q=0.9, */* ;q=0.8")
|
parts := parseAccept("text/html , application/xhtml+xml,application/xml;q=0.9, */* ;q=0.8")
|
||||||
assert.Len(t, parts, 4)
|
assert.Len(t, parts, 4)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user