mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-12 16:48:19 +08:00
Merge e8622bf445ffb81bf4bced0ecfeca2712710a02b into d1a15347b1e45a8ee816193d3578a93bfd73b70f
This commit is contained in:
commit
72d0a6fdf2
18
utils.go
18
utils.go
@ -115,13 +115,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()
|
||||||
}
|
}
|
||||||
@ -132,7 +125,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
|
||||||
@ -156,12 +149,9 @@ 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// safeInt8 converts int to int8 safely, capping at math.MaxInt8
|
// safeInt8 converts int to int8 safely, capping at math.MaxInt8
|
||||||
|
|||||||
@ -55,12 +55,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