Merge e8622bf445ffb81bf4bced0ecfeca2712710a02b into b2b489dbf4826c2c630717a77fd5e42774625410

This commit is contained in:
諏訪原慶斗 2026-01-18 18:02:52 -08:00 committed by GitHub
commit 7ebe73dd8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 20 deletions

View File

@ -121,13 +121,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()
}
@ -138,7 +131,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
@ -162,12 +155,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)