File size: 27,548 Bytes
065fee7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
import pytest

import aiohttp
from aiohttp import content_disposition_filename, parse_content_disposition


class TestParseContentDisposition:
    # http://greenbytes.de/tech/tc2231/

    def test_parse_empty(self) -> None:
        disptype, params = parse_content_disposition(None)
        assert disptype is None
        assert {} == params

    def test_inlonly(self) -> None:
        disptype, params = parse_content_disposition("inline")
        assert "inline" == disptype
        assert {} == params

    def test_inlonlyquoted(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition('"inline"')
        assert disptype is None
        assert {} == params

    def test_semicolon(self) -> None:
        disptype, params = parse_content_disposition(
            'form-data; name="data"; filename="file ; name.mp4"'
        )
        assert disptype == "form-data"
        assert params == {"name": "data", "filename": "file ; name.mp4"}

    def test_inlwithasciifilename(self) -> None:
        disptype, params = parse_content_disposition('inline; filename="foo.html"')
        assert "inline" == disptype
        assert {"filename": "foo.html"} == params

    def test_inlwithfnattach(self) -> None:
        disptype, params = parse_content_disposition(
            'inline; filename="Not an attachment!"'
        )
        assert "inline" == disptype
        assert {"filename": "Not an attachment!"} == params

    def test_attonly(self) -> None:
        disptype, params = parse_content_disposition("attachment")
        assert "attachment" == disptype
        assert {} == params

    def test_attonlyquoted(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition('"attachment"')
        assert disptype is None
        assert {} == params

    def test_attonlyucase(self) -> None:
        disptype, params = parse_content_disposition("ATTACHMENT")
        assert "attachment" == disptype
        assert {} == params

    def test_attwithasciifilename(self) -> None:
        disptype, params = parse_content_disposition('attachment; filename="foo.html"')
        assert "attachment" == disptype
        assert {"filename": "foo.html"} == params

    def test_inlwithasciifilenamepdf(self) -> None:
        disptype, params = parse_content_disposition('attachment; filename="foo.pdf"')
        assert "attachment" == disptype
        assert {"filename": "foo.pdf"} == params

    def test_attwithasciifilename25(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="0000000000111111111122222"'
        )
        assert "attachment" == disptype
        assert {"filename": "0000000000111111111122222"} == params

    def test_attwithasciifilename35(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="00000000001111111111222222222233333"'
        )
        assert "attachment" == disptype
        assert {"filename": "00000000001111111111222222222233333"} == params

    def test_attwithasciifnescapedchar(self) -> None:
        disptype, params = parse_content_disposition(
            r'attachment; filename="f\oo.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "foo.html"} == params

    def test_attwithasciifnescapedquote(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename=""quoting" tested.html"'
        )
        assert "attachment" == disptype
        assert {"filename": '"quoting" tested.html'} == params

    @pytest.mark.skip("need more smart parser which respects quoted text")
    def test_attwithquotedsemicolon(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="Here\'s a semicolon;.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "Here's a semicolon;.html"} == params

    def test_attwithfilenameandextparam(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; foo="bar"; filename="foo.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "foo.html", "foo": "bar"} == params

    def test_attwithfilenameandextparamescaped(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; foo=""\\";filename="foo.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "foo.html", "foo": '"\\'} == params

    def test_attwithasciifilenameucase(self) -> None:
        disptype, params = parse_content_disposition('attachment; FILENAME="foo.html"')
        assert "attachment" == disptype
        assert {"filename": "foo.html"} == params

    def test_attwithasciifilenamenq(self) -> None:
        disptype, params = parse_content_disposition("attachment; filename=foo.html")
        assert "attachment" == disptype
        assert {"filename": "foo.html"} == params

    def test_attwithtokfncommanq(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "attachment; filename=foo,bar.html"
            )
        assert disptype is None
        assert {} == params

    def test_attwithasciifilenamenqs(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "attachment; filename=foo.html ;"
            )
        assert disptype is None
        assert {} == params

    def test_attemptyparam(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition("attachment; ;filename=foo")
        assert disptype is None
        assert {} == params

    def test_attwithasciifilenamenqws(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "attachment; filename=foo bar.html"
            )
        assert disptype is None
        assert {} == params

    def test_attwithfntokensq(self) -> None:
        disptype, params = parse_content_disposition("attachment; filename='foo.html'")
        assert "attachment" == disptype
        assert {"filename": "'foo.html'"} == params

    def test_attwithisofnplain(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="foo-ä.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "foo-ä.html"} == params

    def test_attwithutf8fnplain(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="foo-ä.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "foo-ä.html"} == params

    def test_attwithfnrawpctenca(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="foo-%41.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "foo-%41.html"} == params

    def test_attwithfnusingpct(self) -> None:
        disptype, params = parse_content_disposition('attachment; filename="50%.html"')
        assert "attachment" == disptype
        assert {"filename": "50%.html"} == params

    def test_attwithfnrawpctencaq(self) -> None:
        disptype, params = parse_content_disposition(
            r'attachment; filename="foo-%\41.html"'
        )
        assert "attachment" == disptype
        assert {"filename": r"foo-%41.html"} == params

    def test_attwithnamepct(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="foo-%41.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "foo-%41.html"} == params

    def test_attwithfilenamepctandiso(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="ä-%41.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "ä-%41.html"} == params

    def test_attwithfnrawpctenclong(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="foo-%c3%a4-%e2%82%ac.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "foo-%c3%a4-%e2%82%ac.html"} == params

    def test_attwithasciifilenamews1(self) -> None:
        disptype, params = parse_content_disposition('attachment; filename ="foo.html"')
        assert "attachment" == disptype
        assert {"filename": "foo.html"} == params

    def test_attwith2filenames(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                'attachment; filename="foo.html"; filename="bar.html"'
            )
        assert disptype is None
        assert {} == params

    def test_attfnbrokentoken(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "attachment; filename=foo[1](2).html"
            )
        assert disptype is None
        assert {} == params

    def test_attfnbrokentokeniso(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "attachment; filename=foo-ä.html"
            )
        assert disptype is None
        assert {} == params

    def test_attfnbrokentokenutf(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "attachment; filename=foo-ä.html"
            )
        assert disptype is None
        assert {} == params

    def test_attmissingdisposition(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition("filename=foo.html")
        assert disptype is None
        assert {} == params

    def test_attmissingdisposition2(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition("x=y; filename=foo.html")
        assert disptype is None
        assert {} == params

    def test_attmissingdisposition3(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                '"foo; filename=bar;baz"; filename=qux'
            )
        assert disptype is None
        assert {} == params

    def test_attmissingdisposition4(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "filename=foo.html, filename=bar.html"
            )
        assert disptype is None
        assert {} == params

    def test_emptydisposition(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition("; filename=foo.html")
        assert disptype is None
        assert {} == params

    def test_doublecolon(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                ": inline; attachment; filename=foo.html"
            )
        assert disptype is None
        assert {} == params

    def test_attandinline(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "inline; attachment; filename=foo.html"
            )
        assert disptype is None
        assert {} == params

    def test_attandinline2(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "attachment; inline; filename=foo.html"
            )
        assert disptype is None
        assert {} == params

    def test_attbrokenquotedfn(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                'attachment; filename="foo.html".txt'
            )
        assert disptype is None
        assert {} == params

    def test_attbrokenquotedfn2(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition('attachment; filename="bar')
        assert disptype is None
        assert {} == params

    def test_attbrokenquotedfn3(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                'attachment; filename=foo"bar;baz"qux'
            )
        assert disptype is None
        assert {} == params

    def test_attmultinstances(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "attachment; filename=foo.html, attachment; filename=bar.html"
            )
        assert disptype is None
        assert {} == params

    def test_attmissingdelim(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "attachment; foo=foo filename=bar"
            )
        assert disptype is None
        assert {} == params

    def test_attmissingdelim2(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "attachment; filename=bar foo=foo"
            )
        assert disptype is None
        assert {} == params

    def test_attmissingdelim3(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition("attachment filename=bar")
        assert disptype is None
        assert {} == params

    def test_attreversed(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "filename=foo.html; attachment"
            )
        assert disptype is None
        assert {} == params

    def test_attconfusedparam(self) -> None:
        disptype, params = parse_content_disposition("attachment; xfilename=foo.html")
        assert "attachment" == disptype
        assert {"xfilename": "foo.html"} == params

    def test_attabspath(self) -> None:
        disptype, params = parse_content_disposition('attachment; filename="/foo.html"')
        assert "attachment" == disptype
        assert {"filename": "foo.html"} == params

    def test_attabspathwin(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="\\foo.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "foo.html"} == params

    def test_attcdate(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; creation-date="Wed, 12 Feb 1997 16:29:51 -0500"'
        )
        assert "attachment" == disptype
        assert {"creation-date": "Wed, 12 Feb 1997 16:29:51 -0500"} == params

    def test_attmdate(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; modification-date="Wed, 12 Feb 1997 16:29:51 -0500"'
        )
        assert "attachment" == disptype
        assert {"modification-date": "Wed, 12 Feb 1997 16:29:51 -0500"} == params

    def test_dispext(self) -> None:
        disptype, params = parse_content_disposition("foobar")
        assert "foobar" == disptype
        assert {} == params

    def test_dispextbadfn(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; example="filename=example.txt"'
        )
        assert "attachment" == disptype
        assert {"example": "filename=example.txt"} == params

    def test_attwithisofn2231iso(self) -> None:
        disptype, params = parse_content_disposition(
            "attachment; filename*=iso-8859-1''foo-%E4.html"
        )
        assert "attachment" == disptype
        assert {"filename*": "foo-ä.html"} == params

    def test_attwithfn2231utf8(self) -> None:
        disptype, params = parse_content_disposition(
            "attachment; filename*=UTF-8''foo-%c3%a4-%e2%82%ac.html"
        )
        assert "attachment" == disptype
        assert {"filename*": "foo-ä-€.html"} == params

    def test_attwithfn2231noc(self) -> None:
        disptype, params = parse_content_disposition(
            "attachment; filename*=''foo-%c3%a4-%e2%82%ac.html"
        )
        assert "attachment" == disptype
        assert {"filename*": "foo-ä-€.html"} == params

    def test_attwithfn2231utf8comp(self) -> None:
        disptype, params = parse_content_disposition(
            "attachment; filename*=UTF-8''foo-a%cc%88.html"
        )
        assert "attachment" == disptype
        assert {"filename*": "foo-ä.html"} == params

    @pytest.mark.skip("should raise decoding error: %82 is invalid for latin1")
    def test_attwithfn2231utf8_bad(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionParam):
            disptype, params = parse_content_disposition(
                "attachment; filename*=iso-8859-1''foo-%c3%a4-%e2%82%ac.html"
            )
        assert "attachment" == disptype
        assert {} == params

    @pytest.mark.skip("should raise decoding error: %E4 is invalid for utf-8")
    def test_attwithfn2231iso_bad(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionParam):
            disptype, params = parse_content_disposition(
                "attachment; filename*=utf-8''foo-%E4.html"
            )
        assert "attachment" == disptype
        assert {} == params

    def test_attwithfn2231ws1(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionParam):
            disptype, params = parse_content_disposition(
                "attachment; filename *=UTF-8''foo-%c3%a4.html"
            )
        assert "attachment" == disptype
        assert {} == params

    def test_attwithfn2231ws2(self) -> None:
        disptype, params = parse_content_disposition(
            "attachment; filename*= UTF-8''foo-%c3%a4.html"
        )
        assert "attachment" == disptype
        assert {"filename*": "foo-ä.html"} == params

    def test_attwithfn2231ws3(self) -> None:
        disptype, params = parse_content_disposition(
            "attachment; filename* =UTF-8''foo-%c3%a4.html"
        )
        assert "attachment" == disptype
        assert {"filename*": "foo-ä.html"} == params

    def test_attwithfn2231quot(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionParam):
            disptype, params = parse_content_disposition(
                "attachment; filename*=\"UTF-8''foo-%c3%a4.html\""
            )
        assert "attachment" == disptype
        assert {} == params

    def test_attwithfn2231quot2(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionParam):
            disptype, params = parse_content_disposition(
                'attachment; filename*="foo%20bar.html"'
            )
        assert "attachment" == disptype
        assert {} == params

    def test_attwithfn2231singleqmissing(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionParam):
            disptype, params = parse_content_disposition(
                "attachment; filename*=UTF-8'foo-%c3%a4.html"
            )
        assert "attachment" == disptype
        assert {} == params

    @pytest.mark.skip("urllib.parse.unquote is tolerate to standalone % chars")
    def test_attwithfn2231nbadpct1(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionParam):
            disptype, params = parse_content_disposition(
                "attachment; filename*=UTF-8''foo%"
            )
        assert "attachment" == disptype
        assert {} == params

    @pytest.mark.skip("urllib.parse.unquote is tolerate to standalone % chars")
    def test_attwithfn2231nbadpct2(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionParam):
            disptype, params = parse_content_disposition(
                "attachment; filename*=UTF-8''f%oo.html"
            )
        assert "attachment" == disptype
        assert {} == params

    def test_attwithfn2231dpct(self) -> None:
        disptype, params = parse_content_disposition(
            "attachment; filename*=UTF-8''A-%2541.html"
        )
        assert "attachment" == disptype
        assert {"filename*": "A-%41.html"} == params

    def test_attwithfn2231abspathdisguised(self) -> None:
        disptype, params = parse_content_disposition(
            "attachment; filename*=UTF-8''%5cfoo.html"
        )
        assert "attachment" == disptype
        assert {"filename*": "\\foo.html"} == params

    def test_attfncont(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename*0="foo."; filename*1="html"'
        )
        assert "attachment" == disptype
        assert {"filename*0": "foo.", "filename*1": "html"} == params

    def test_attfncontqs(self) -> None:
        disptype, params = parse_content_disposition(
            r'attachment; filename*0="foo"; filename*1="\b\a\r.html"'
        )
        assert "attachment" == disptype
        assert {"filename*0": "foo", "filename*1": "bar.html"} == params

    def test_attfncontenc(self) -> None:
        disptype, params = parse_content_disposition(
            "attachment; filename*0*=UTF-8" 'foo-%c3%a4; filename*1=".html"'
        )
        assert "attachment" == disptype
        assert {"filename*0*": "UTF-8" "foo-%c3%a4", "filename*1": ".html"} == params

    def test_attfncontlz(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename*0="foo"; filename*01="bar"'
        )
        assert "attachment" == disptype
        assert {"filename*0": "foo", "filename*01": "bar"} == params

    def test_attfncontnc(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename*0="foo"; filename*2="bar"'
        )
        assert "attachment" == disptype
        assert {"filename*0": "foo", "filename*2": "bar"} == params

    def test_attfnconts1(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename*0="foo."; filename*2="html"'
        )
        assert "attachment" == disptype
        assert {"filename*0": "foo.", "filename*2": "html"} == params

    def test_attfncontord(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename*1="bar"; filename*0="foo"'
        )
        assert "attachment" == disptype
        assert {"filename*0": "foo", "filename*1": "bar"} == params

    def test_attfnboth(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="foo-ae.html";' " filename*=UTF-8''foo-%c3%a4.html"
        )
        assert "attachment" == disptype
        assert {"filename": "foo-ae.html", "filename*": "foo-ä.html"} == params

    def test_attfnboth2(self) -> None:
        disptype, params = parse_content_disposition(
            "attachment; filename*=UTF-8''foo-%c3%a4.html;" ' filename="foo-ae.html"'
        )
        assert "attachment" == disptype
        assert {"filename": "foo-ae.html", "filename*": "foo-ä.html"} == params

    def test_attfnboth3(self) -> None:
        disptype, params = parse_content_disposition(
            "attachment; filename*0*=ISO-8859-15''euro-sign%3d%a4;"
            " filename*=ISO-8859-1''currency-sign%3d%a4"
        )
        assert "attachment" == disptype
        assert {
            "filename*": "currency-sign=¤",
            "filename*0*": "ISO-8859-15''euro-sign%3d%a4",
        } == params

    def test_attnewandfn(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; foobar=x; filename="foo.html"'
        )
        assert "attachment" == disptype
        assert {"foobar": "x", "filename": "foo.html"} == params

    def test_attrfc2047token(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionHeader):
            disptype, params = parse_content_disposition(
                "attachment; filename==?ISO-8859-1?Q?foo-=E4.html?="
            )
        assert disptype is None
        assert {} == params

    def test_attrfc2047quoted(self) -> None:
        disptype, params = parse_content_disposition(
            'attachment; filename="=?ISO-8859-1?Q?foo-=E4.html?="'
        )
        assert "attachment" == disptype
        assert {"filename": "=?ISO-8859-1?Q?foo-=E4.html?="} == params

    def test_bad_continuous_param(self) -> None:
        with pytest.warns(aiohttp.BadContentDispositionParam):
            disptype, params = parse_content_disposition(
                "attachment; filename*0=foo bar"
            )
        assert "attachment" == disptype
        assert {} == params


class TestContentDispositionFilename:
    # http://greenbytes.de/tech/tc2231/

    def test_no_filename(self) -> None:
        assert content_disposition_filename({}) is None
        assert content_disposition_filename({"foo": "bar"}) is None

    def test_filename(self) -> None:
        params = {"filename": "foo.html"}
        assert "foo.html" == content_disposition_filename(params)

    def test_filename_ext(self) -> None:
        params = {"filename*": "файл.html"}
        assert "файл.html" == content_disposition_filename(params)

    def test_attfncont(self) -> None:
        params = {"filename*0": "foo.", "filename*1": "html"}
        assert "foo.html" == content_disposition_filename(params)

    def test_attfncontqs(self) -> None:
        params = {"filename*0": "foo", "filename*1": "bar.html"}
        assert "foobar.html" == content_disposition_filename(params)

    def test_attfncontenc(self) -> None:
        params = {"filename*0*": "UTF-8''foo-%c3%a4", "filename*1": ".html"}
        assert "foo-ä.html" == content_disposition_filename(params)

    def test_attfncontlz(self) -> None:
        params = {"filename*0": "foo", "filename*01": "bar"}
        assert "foo" == content_disposition_filename(params)

    def test_attfncontnc(self) -> None:
        params = {"filename*0": "foo", "filename*2": "bar"}
        assert "foo" == content_disposition_filename(params)

    def test_attfnconts1(self) -> None:
        params = {"filename*1": "foo", "filename*2": "bar"}
        assert content_disposition_filename(params) is None

    def test_attfnboth(self) -> None:
        params = {"filename": "foo-ae.html", "filename*": "foo-ä.html"}
        assert "foo-ä.html" == content_disposition_filename(params)

    def test_attfnboth3(self) -> None:
        params = {
            "filename*0*": "ISO-8859-15''euro-sign%3d%a4",
            "filename*": "currency-sign=¤",
        }
        assert "currency-sign=¤" == content_disposition_filename(params)

    def test_attrfc2047quoted(self) -> None:
        params = {"filename": "=?ISO-8859-1?Q?foo-=E4.html?="}
        assert "=?ISO-8859-1?Q?foo-=E4.html?=" == content_disposition_filename(params)