Merge e8622bf445ffb81bf4bced0ecfeca2712710a02b into d1a15347b1e45a8ee816193d3578a93bfd73b70f

This commit is contained in:
諏訪原慶斗 2025-12-13 13:27:48 -08:00 committed by GitHub
commit 72d0a6fdf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 20 deletions

View File

@ -115,13 +115,6 @@ func parseAccept(acceptHeader string) []string {
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 {
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
}
@ -132,7 +125,7 @@ func joinPaths(absolutePath, relativePath string) string {
}
finalPath := path.Join(absolutePath, relativePath)
if lastChar(relativePath) == '/' && lastChar(finalPath) != '/' {
if strings.HasSuffix(relativePath, "/") && !strings.HasSuffix(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
func isASCII(s string) bool {
for i := 0; i < len(s); i++ {
if s[i] > unicode.MaxASCII {
return false
}
}
return true
return !strings.ContainsFunc(s, func(r rune) bool {
return r > unicode.MaxASCII
})
}
// safeInt8 converts int to int8 safely, capping at math.MaxInt8

View File

@ -55,12 +55,6 @@ func TestWrap(t *testing.T) {
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) {
parts := parseAccept("text/html , application/xhtml+xml,application/xml;q=0.9, */* ;q=0.8")
assert.Len(t, parts, 4)