Skip to content

Commit

Permalink
[release-branch.go1.2] net/textproto: fix CanonicalMIMEHeaderKey panic
Browse files Browse the repository at this point in the history
««« CL 21450043 / e081962da65c
net/textproto: fix CanonicalMIMEHeaderKey panic

Fixes #6712

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/21450043
»»»

R=golang-dev
CC=golang-dev
https://golang.org/cl/25640044
  • Loading branch information
adg committed Nov 13, 2013
1 parent 065f8fd commit 4f8794d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/pkg/net/textproto/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,10 @@ func canonicalMIMEHeaderKey(a []byte) string {
// and upper case after each dash.
// (Host, User-Agent, If-Modified-Since).
// MIME headers are ASCII only, so no Unicode issues.
if a[i] == ' ' {
a[i] = '-'
upper = true
continue
}
c := a[i]
if upper && 'a' <= c && c <= 'z' {
if c == ' ' {
c = '-'
} else if upper && 'a' <= c && c <= 'z' {
c -= toLower
} else if !upper && 'A' <= c && c <= 'Z' {
c += toLower
Expand Down
4 changes: 4 additions & 0 deletions src/pkg/net/textproto/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ var canonicalHeaderKeyTests = []canonicalHeaderKeyTest{
{"user-agent", "User-Agent"},
{"USER-AGENT", "User-Agent"},
{"üser-agenT", "üser-Agent"}, // non-ASCII unchanged

// This caused a panic due to mishandling of a space:
{"C Ontent-Transfer-Encoding", "C-Ontent-Transfer-Encoding"},
{"foo bar", "Foo-Bar"},
}

func TestCanonicalMIMEHeaderKey(t *testing.T) {
Expand Down

0 comments on commit 4f8794d

Please sign in to comment.