File tree 1 file changed +12
-3
lines changed
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -206,11 +206,20 @@ func TestLineBreaker(t *testing.T) {
206
206
}
207
207
208
208
func TestFuzz (t * testing.T ) {
209
+ // PEM is a text-based format. Assume header fields with leading/trailing spaces
210
+ // or embedded newlines will not round trip correctly and don't need to be tested.
211
+ isBad := func (s string ) bool {
212
+ return strings .ContainsAny (s , "\r \n " ) || strings .TrimSpace (s ) != s
213
+ }
214
+
209
215
testRoundtrip := func (block Block ) bool {
216
+ if isBad (block .Type ) {
217
+ return true
218
+ }
210
219
for key , val := range block .Headers {
211
- if strings . ContainsAny ( key , ": \r \n " ) || strings . ContainsAny ( val , " \r \n " ) || strings . TrimSpace ( key ) != key || strings . TrimSpace ( val ) != val {
212
- // Keys with colons or newlines cannot be encoded.
213
- // Keys/values with surrounding spaces might lose theirs.
220
+ // Reject bad key/ val.
221
+ // Also, keys with colons cannot be encoded, because : is the key: val separator .
222
+ if isBad ( key ) || isBad ( val ) || strings . Contains ( key , ":" ) {
214
223
return true
215
224
}
216
225
}
You can’t perform that action at this time.
0 commit comments