@@ -147,6 +147,19 @@ var writeSetCookiesTests = []struct {
147
147
& Cookie {Name : "a\r b" , Value : "v" },
148
148
`` ,
149
149
},
150
+ // Quoted values (issue #46443)
151
+ {
152
+ & Cookie {Name : "cookie" , Value : "quoted" , Quoted : true },
153
+ `cookie="quoted"` ,
154
+ },
155
+ {
156
+ & Cookie {Name : "cookie" , Value : "quoted with spaces" , Quoted : true },
157
+ `cookie="quoted with spaces"` ,
158
+ },
159
+ {
160
+ & Cookie {Name : "cookie" , Value : "quoted,with,commas" , Quoted : true },
161
+ `cookie="quoted,with,commas"` ,
162
+ },
150
163
}
151
164
152
165
func TestWriteSetCookies (t * testing.T ) {
@@ -215,6 +228,15 @@ var addCookieTests = []struct {
215
228
},
216
229
"cookie-1=v$1; cookie-2=v$2; cookie-3=v$3" ,
217
230
},
231
+ // Quoted values (issue #46443)
232
+ {
233
+ []* Cookie {
234
+ {Name : "cookie-1" , Value : "quoted" , Quoted : true },
235
+ {Name : "cookie-2" , Value : "quoted with spaces" , Quoted : true },
236
+ {Name : "cookie-3" , Value : "quoted,with,commas" , Quoted : true },
237
+ },
238
+ `cookie-1="quoted"; cookie-2="quoted with spaces"; cookie-3="quoted,with,commas"` ,
239
+ },
218
240
}
219
241
220
242
func TestAddCookie (t * testing.T ) {
@@ -326,37 +348,42 @@ var readSetCookiesTests = []struct {
326
348
},
327
349
{
328
350
Header {"Set-Cookie" : {`special-2=" z"` }},
329
- []* Cookie {{Name : "special-2" , Value : " z" , Raw : `special-2=" z"` }},
351
+ []* Cookie {{Name : "special-2" , Value : " z" , Quoted : true , Raw : `special-2=" z"` }},
330
352
},
331
353
{
332
354
Header {"Set-Cookie" : {`special-3="a "` }},
333
- []* Cookie {{Name : "special-3" , Value : "a " , Raw : `special-3="a "` }},
355
+ []* Cookie {{Name : "special-3" , Value : "a " , Quoted : true , Raw : `special-3="a "` }},
334
356
},
335
357
{
336
358
Header {"Set-Cookie" : {`special-4=" "` }},
337
- []* Cookie {{Name : "special-4" , Value : " " , Raw : `special-4=" "` }},
359
+ []* Cookie {{Name : "special-4" , Value : " " , Quoted : true , Raw : `special-4=" "` }},
338
360
},
339
361
{
340
362
Header {"Set-Cookie" : {`special-5=a,z` }},
341
363
[]* Cookie {{Name : "special-5" , Value : "a,z" , Raw : `special-5=a,z` }},
342
364
},
343
365
{
344
366
Header {"Set-Cookie" : {`special-6=",z"` }},
345
- []* Cookie {{Name : "special-6" , Value : ",z" , Raw : `special-6=",z"` }},
367
+ []* Cookie {{Name : "special-6" , Value : ",z" , Quoted : true , Raw : `special-6=",z"` }},
346
368
},
347
369
{
348
370
Header {"Set-Cookie" : {`special-7=a,` }},
349
371
[]* Cookie {{Name : "special-7" , Value : "a," , Raw : `special-7=a,` }},
350
372
},
351
373
{
352
374
Header {"Set-Cookie" : {`special-8=","` }},
353
- []* Cookie {{Name : "special-8" , Value : "," , Raw : `special-8=","` }},
375
+ []* Cookie {{Name : "special-8" , Value : "," , Quoted : true , Raw : `special-8=","` }},
354
376
},
355
377
// Make sure we can properly read back the Set-Cookie headers
356
378
// for names containing spaces:
357
379
{
358
380
Header {"Set-Cookie" : {`special-9 =","` }},
359
- []* Cookie {{Name : "special-9" , Value : "," , Raw : `special-9 =","` }},
381
+ []* Cookie {{Name : "special-9" , Value : "," , Quoted : true , Raw : `special-9 =","` }},
382
+ },
383
+ // Quoted values (issue #46443)
384
+ {
385
+ Header {"Set-Cookie" : {`cookie="quoted"` }},
386
+ []* Cookie {{Name : "cookie" , Value : "quoted" , Quoted : true , Raw : `cookie="quoted"` }},
360
387
},
361
388
362
389
// TODO(bradfitz): users have reported seeing this in the
@@ -425,15 +452,15 @@ var readCookiesTests = []struct {
425
452
Header {"Cookie" : {`Cookie-1="v$1"; c2="v2"` }},
426
453
"" ,
427
454
[]* Cookie {
428
- {Name : "Cookie-1" , Value : "v$1" },
429
- {Name : "c2" , Value : "v2" },
455
+ {Name : "Cookie-1" , Value : "v$1" , Quoted : true },
456
+ {Name : "c2" , Value : "v2" , Quoted : true },
430
457
},
431
458
},
432
459
{
433
460
Header {"Cookie" : {`Cookie-1="v$1"; c2=v2;` }},
434
461
"" ,
435
462
[]* Cookie {
436
- {Name : "Cookie-1" , Value : "v$1" },
463
+ {Name : "Cookie-1" , Value : "v$1" , Quoted : true },
437
464
{Name : "c2" , Value : "v2" },
438
465
},
439
466
},
@@ -486,23 +513,26 @@ func TestCookieSanitizeValue(t *testing.T) {
486
513
log .SetOutput (& logbuf )
487
514
488
515
tests := []struct {
489
- in , want string
516
+ in string
517
+ quoted bool
518
+ want string
490
519
}{
491
- {"foo" , "foo" },
492
- {"foo;bar" , "foobar" },
493
- {"foo\\ bar" , "foobar" },
494
- {"foo\" bar" , "foobar" },
495
- {"\x00 \x7e \x7f \x80 " , "\x7e " },
496
- {`"withquotes"` , "withquotes" },
497
- {"a z" , `"a z"` },
498
- {" z" , `" z"` },
499
- {"a " , `"a "` },
500
- {"a,z" , `"a,z"` },
501
- {",z" , `",z"` },
502
- {"a," , `"a,"` },
520
+ {"foo" , false , "foo" },
521
+ {"foo;bar" , false , "foobar" },
522
+ {"foo\\ bar" , false , "foobar" },
523
+ {"foo\" bar" , false , "foobar" },
524
+ {"\x00 \x7e \x7f \x80 " , false , "\x7e " },
525
+ {`withquotes` , true , `"withquotes"` },
526
+ {`"withquotes"` , true , `"withquotes"` }, // double quotes are not valid octets
527
+ {"a z" , false , `"a z"` },
528
+ {" z" , false , `" z"` },
529
+ {"a " , false , `"a "` },
530
+ {"a,z" , false , `"a,z"` },
531
+ {",z" , false , `",z"` },
532
+ {"a," , false , `"a,"` },
503
533
}
504
534
for _ , tt := range tests {
505
- if got := sanitizeCookieValue (tt .in ); got != tt .want {
535
+ if got := sanitizeCookieValue (tt .in , tt . quoted ); got != tt .want {
506
536
t .Errorf ("sanitizeCookieValue(%q) = %q; want %q" , tt .in , got , tt .want )
507
537
}
508
538
}
@@ -668,7 +698,7 @@ func TestParseCookie(t *testing.T) {
668
698
},
669
699
{
670
700
line : `Cookie-1="v$1";c2="v2"` ,
671
- cookies : []* Cookie {{Name : "Cookie-1" , Value : "v$1" }, {Name : "c2" , Value : "v2" }},
701
+ cookies : []* Cookie {{Name : "Cookie-1" , Value : "v$1" , Quoted : true }, {Name : "c2" , Value : "v2" , Quoted : true }},
672
702
},
673
703
{
674
704
line : "k1=" ,
@@ -800,37 +830,37 @@ func TestParseSetCookie(t *testing.T) {
800
830
},
801
831
{
802
832
line : `special-2=" z"` ,
803
- cookie : & Cookie {Name : "special-2" , Value : " z" , Raw : `special-2=" z"` },
833
+ cookie : & Cookie {Name : "special-2" , Value : " z" , Quoted : true , Raw : `special-2=" z"` },
804
834
},
805
835
{
806
836
line : `special-3="a "` ,
807
- cookie : & Cookie {Name : "special-3" , Value : "a " , Raw : `special-3="a "` },
837
+ cookie : & Cookie {Name : "special-3" , Value : "a " , Quoted : true , Raw : `special-3="a "` },
808
838
},
809
839
{
810
840
line : `special-4=" "` ,
811
- cookie : & Cookie {Name : "special-4" , Value : " " , Raw : `special-4=" "` },
841
+ cookie : & Cookie {Name : "special-4" , Value : " " , Quoted : true , Raw : `special-4=" "` },
812
842
},
813
843
{
814
844
line : `special-5=a,z` ,
815
845
cookie : & Cookie {Name : "special-5" , Value : "a,z" , Raw : `special-5=a,z` },
816
846
},
817
847
{
818
848
line : `special-6=",z"` ,
819
- cookie : & Cookie {Name : "special-6" , Value : ",z" , Raw : `special-6=",z"` },
849
+ cookie : & Cookie {Name : "special-6" , Value : ",z" , Quoted : true , Raw : `special-6=",z"` },
820
850
},
821
851
{
822
852
line : `special-7=a,` ,
823
853
cookie : & Cookie {Name : "special-7" , Value : "a," , Raw : `special-7=a,` },
824
854
},
825
855
{
826
856
line : `special-8=","` ,
827
- cookie : & Cookie {Name : "special-8" , Value : "," , Raw : `special-8=","` },
857
+ cookie : & Cookie {Name : "special-8" , Value : "," , Quoted : true , Raw : `special-8=","` },
828
858
},
829
859
// Make sure we can properly read back the Set-Cookie headers
830
860
// for names containing spaces:
831
861
{
832
862
line : `special-9 =","` ,
833
- cookie : & Cookie {Name : "special-9" , Value : "," , Raw : `special-9 =","` },
863
+ cookie : & Cookie {Name : "special-9" , Value : "," , Quoted : true , Raw : `special-9 =","` },
834
864
},
835
865
{
836
866
line : "" ,
0 commit comments