Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,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()
}
Expand All @@ -131,7 +124,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
Expand All @@ -155,10 +148,7 @@ 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
})
}
6 changes: 0 additions & 6 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,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)
Expand Down
Loading