Skip to content

Commit

Permalink
Use strings.ToLower in ServeMux.match (#1010)
Browse files Browse the repository at this point in the history
This has been a long standing TODO. golang.org/cl/137575 was included in
go1.12 which is the oldest officially supported release.
  • Loading branch information
tmthrgd authored and miekg committed Sep 21, 2019
1 parent ab6ac40 commit ba5bfd0
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions serve_mux.go
Expand Up @@ -36,33 +36,9 @@ func (mux *ServeMux) match(q string, t uint16) Handler {
return nil
}

var handler Handler

// TODO(tmthrgd): Once https://go-review.googlesource.com/c/go/+/137575
// lands in a go release, replace the following with strings.ToLower.
var sb strings.Builder
for i := 0; i < len(q); i++ {
c := q[i]
if !(c >= 'A' && c <= 'Z') {
continue
}

sb.Grow(len(q))
sb.WriteString(q[:i])

for ; i < len(q); i++ {
c := q[i]
if c >= 'A' && c <= 'Z' {
c += 'a' - 'A'
}

sb.WriteByte(c)
}

q = sb.String()
break
}
q = strings.ToLower(q)

var handler Handler
for off, end := 0, false; !end; off, end = NextLabel(q, off) {
if h, ok := mux.z[q[off:]]; ok {
if t != TypeDS {
Expand Down

0 comments on commit ba5bfd0

Please sign in to comment.