Skip to content

Commit

Permalink
encoding/pem: do not try to round trip value with leading/trailing space
Browse files Browse the repository at this point in the history
The header is literally

	Key: Value

If the value or the key has leading or trailing spaces, those will
be lost by the round trip.

Found because testing/quick returns different values now.

Change-Id: I0f574bdbb5990689509c24309854d8f814b5efa0
Reviewed-on: https://go-review.googlesource.com/39211
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
rsc committed Apr 3, 2017
1 parent 64f00fb commit 65c17a0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/encoding/pem/pem_test.go
Expand Up @@ -207,9 +207,10 @@ func TestLineBreaker(t *testing.T) {

func TestFuzz(t *testing.T) {
testRoundtrip := func(block Block) bool {
for key := range block.Headers {
if strings.Contains(key, ":") {
// Keys with colons cannot be encoded.
for key, val := range block.Headers {
if strings.ContainsAny(key, ":\r\n") || strings.ContainsAny(val, "\r\n") || strings.TrimSpace(key) != key || strings.TrimSpace(val) != val {
// Keys with colons or newlines cannot be encoded.
// Keys/values with surrounding spaces might lose theirs.
return true
}
}
Expand Down

0 comments on commit 65c17a0

Please sign in to comment.