OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_content_disposition.h" | 5 #include "net/http/http_content_disposition.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
(...skipping 16 matching lines...) Expand all Loading... |
27 {"attachment; filename=abcde.pdf", "", L"abcde.pdf"}, | 27 {"attachment; filename=abcde.pdf", "", L"abcde.pdf"}, |
28 {"attachment; name=abcde.pdf", "", L"abcde.pdf"}, | 28 {"attachment; name=abcde.pdf", "", L"abcde.pdf"}, |
29 {"attachment; filename=abc,de.pdf", "", L"abc,de.pdf"}, | 29 {"attachment; filename=abc,de.pdf", "", L"abc,de.pdf"}, |
30 {"filename=abcde.pdf", "", L"abcde.pdf"}, | 30 {"filename=abcde.pdf", "", L"abcde.pdf"}, |
31 {"filename= abcde.pdf", "", L"abcde.pdf"}, | 31 {"filename= abcde.pdf", "", L"abcde.pdf"}, |
32 {"filename =abcde.pdf", "", L"abcde.pdf"}, | 32 {"filename =abcde.pdf", "", L"abcde.pdf"}, |
33 {"filename = abcde.pdf", "", L"abcde.pdf"}, | 33 {"filename = abcde.pdf", "", L"abcde.pdf"}, |
34 {"filename\t=abcde.pdf", "", L"abcde.pdf"}, | 34 {"filename\t=abcde.pdf", "", L"abcde.pdf"}, |
35 {"filename \t\t =abcde.pdf", "", L"abcde.pdf"}, | 35 {"filename \t\t =abcde.pdf", "", L"abcde.pdf"}, |
36 {"name=abcde.pdf", "", L"abcde.pdf"}, | 36 {"name=abcde.pdf", "", L"abcde.pdf"}, |
37 {"inline; filename=\"abc%20de.pdf\"", "", | 37 {"inline; filename=\"abc%20de.pdf\"", "", L"abc de.pdf"}, |
38 L"abc de.pdf"}, | |
39 // Unbalanced quotation mark | 38 // Unbalanced quotation mark |
40 {"filename=\"abcdef.pdf", "", L"abcdef.pdf"}, | 39 {"filename=\"abcdef.pdf", "", L"abcdef.pdf"}, |
41 // Whitespaces are converted to a space. | 40 // Whitespaces are converted to a space. |
42 {"inline; filename=\"abc \t\nde.pdf\"", "", | 41 {"inline; filename=\"abc \t\nde.pdf\"", "", L"abc de.pdf"}, |
43 L"abc de.pdf"}, | |
44 // %-escaped UTF-8 | 42 // %-escaped UTF-8 |
45 {"attachment; filename=\"%EC%98%88%EC%88%A0%20" | 43 {"attachment; filename=\"%EC%98%88%EC%88%A0%20" |
46 "%EC%98%88%EC%88%A0.jpg\"", "", L"\xc608\xc220 \xc608\xc220.jpg"}, | 44 "%EC%98%88%EC%88%A0.jpg\"", |
| 45 "", L"\xc608\xc220 \xc608\xc220.jpg"}, |
47 {"attachment; filename=\"%F0%90%8C%B0%F0%90%8C%B1" | 46 {"attachment; filename=\"%F0%90%8C%B0%F0%90%8C%B1" |
48 "abc.jpg\"", "", L"\U00010330\U00010331abc.jpg"}, | 47 "abc.jpg\"", |
| 48 "", L"\U00010330\U00010331abc.jpg"}, |
49 {"attachment; filename=\"%EC%98%88%EC%88%A0 \n" | 49 {"attachment; filename=\"%EC%98%88%EC%88%A0 \n" |
50 "%EC%98%88%EC%88%A0.jpg\"", "", L"\xc608\xc220 \xc608\xc220.jpg"}, | 50 "%EC%98%88%EC%88%A0.jpg\"", |
| 51 "", L"\xc608\xc220 \xc608\xc220.jpg"}, |
51 // RFC 2047 with various charsets and Q/B encodings | 52 // RFC 2047 with various charsets and Q/B encodings |
52 {"attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" | 53 {"attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" |
53 "D13=2Epng?=\"", "", L"\x82b8\x8853" L"3.png"}, | 54 "D13=2Epng?=\"", |
54 {"attachment; filename==?eUc-Kr?b?v7m8+iAzLnBuZw==?=", | 55 "", |
55 "", L"\xc608\xc220 3.png"}, | 56 L"\x82b8\x8853" |
| 57 L"3.png"}, |
| 58 {"attachment; filename==?eUc-Kr?b?v7m8+iAzLnBuZw==?=", "", |
| 59 L"\xc608\xc220 3.png"}, |
56 {"attachment; filename==?utf-8?Q?=E8=8A=B8=E8" | 60 {"attachment; filename==?utf-8?Q?=E8=8A=B8=E8" |
57 "=A1=93_3=2Epng?=", "", L"\x82b8\x8853 3.png"}, | 61 "=A1=93_3=2Epng?=", |
| 62 "", L"\x82b8\x8853 3.png"}, |
58 {"attachment; filename==?utf-8?Q?=F0=90=8C=B0" | 63 {"attachment; filename==?utf-8?Q?=F0=90=8C=B0" |
59 "_3=2Epng?=", "", L"\U00010330 3.png"}, | 64 "_3=2Epng?=", |
60 {"inline; filename=\"=?iso88591?Q?caf=e9_=2epng?=\"", | 65 "", L"\U00010330 3.png"}, |
61 "", L"caf\x00e9 .png"}, | 66 {"inline; filename=\"=?iso88591?Q?caf=e9_=2epng?=\"", "", |
| 67 L"caf\x00e9 .png"}, |
62 // Space after an encoded word should be removed. | 68 // Space after an encoded word should be removed. |
63 {"inline; filename=\"=?iso88591?Q?caf=E9_?= .png\"", | 69 {"inline; filename=\"=?iso88591?Q?caf=E9_?= .png\"", "", L"caf\x00e9 .png"}, |
64 "", L"caf\x00e9 .png"}, | |
65 // Two encoded words with different charsets (not very likely to be emitted | 70 // Two encoded words with different charsets (not very likely to be emitted |
66 // by web servers in the wild). Spaces between them are removed. | 71 // by web servers in the wild). Spaces between them are removed. |
67 {"inline; filename=\"=?euc-kr?b?v7m8+iAz?=" | 72 {"inline; filename=\"=?euc-kr?b?v7m8+iAz?=" |
68 " =?ksc5601?q?=BF=B9=BC=FA=2Epng?=\"", "", | 73 " =?ksc5601?q?=BF=B9=BC=FA=2Epng?=\"", |
69 L"\xc608\xc220 3\xc608\xc220.png"}, | 74 "", L"\xc608\xc220 3\xc608\xc220.png"}, |
70 {"attachment; filename=\"=?windows-1252?Q?caf=E9?=" | 75 {"attachment; filename=\"=?windows-1252?Q?caf=E9?=" |
71 " =?iso-8859-7?b?4eI=?= .png\"", "", L"caf\x00e9\x03b1\x03b2.png"}, | 76 " =?iso-8859-7?b?4eI=?= .png\"", |
| 77 "", L"caf\x00e9\x03b1\x03b2.png"}, |
72 // Non-ASCII string is passed through and treated as UTF-8 as long as | 78 // Non-ASCII string is passed through and treated as UTF-8 as long as |
73 // it's valid as UTF-8 and regardless of |referrer_charset|. | 79 // it's valid as UTF-8 and regardless of |referrer_charset|. |
74 {"attachment; filename=caf\xc3\xa9.png", | 80 {"attachment; filename=caf\xc3\xa9.png", "iso-8859-1", L"caf\x00e9.png"}, |
75 "iso-8859-1", L"caf\x00e9.png"}, | 81 {"attachment; filename=caf\xc3\xa9.png", "", L"caf\x00e9.png"}, |
76 {"attachment; filename=caf\xc3\xa9.png", | |
77 "", L"caf\x00e9.png"}, | |
78 // Non-ASCII/Non-UTF-8 string. Fall back to the referrer charset. | 82 // Non-ASCII/Non-UTF-8 string. Fall back to the referrer charset. |
79 {"attachment; filename=caf\xe5.png", | 83 {"attachment; filename=caf\xe5.png", "windows-1253", L"caf\x03b5.png"}, |
80 "windows-1253", L"caf\x03b5.png"}, | |
81 #if 0 | 84 #if 0 |
82 // Non-ASCII/Non-UTF-8 string. Fall back to the native codepage. | 85 // Non-ASCII/Non-UTF-8 string. Fall back to the native codepage. |
83 // TODO(jungshik): We need to set the OS default codepage | 86 // TODO(jungshik): We need to set the OS default codepage |
84 // to a specific value before testing. On Windows, we can use | 87 // to a specific value before testing. On Windows, we can use |
85 // SetThreadLocale(). | 88 // SetThreadLocale(). |
86 {"attachment; filename=\xb0\xa1\xb0\xa2.png", | 89 {"attachment; filename=\xb0\xa1\xb0\xa2.png", |
87 "", L"\xac00\xac01.png"}, | 90 "", L"\xac00\xac01.png"}, |
88 #endif | 91 #endif |
89 // Failure cases | 92 // Failure cases |
90 // Invalid hex-digit "G" | 93 // Invalid hex-digit "G" |
91 {"attachment; filename==?iiso88591?Q?caf=EG?=", "", | 94 {"attachment; filename==?iiso88591?Q?caf=EG?=", "", L""}, |
92 L""}, | |
93 // Incomplete RFC 2047 encoded-word (missing '='' at the end) | 95 // Incomplete RFC 2047 encoded-word (missing '='' at the end) |
94 {"attachment; filename==?iso88591?Q?caf=E3?", "", L""}, | 96 {"attachment; filename==?iso88591?Q?caf=E3?", "", L""}, |
95 // Extra character at the end of an encoded word | 97 // Extra character at the end of an encoded word |
96 {"attachment; filename==?iso88591?Q?caf=E3?==", | 98 {"attachment; filename==?iso88591?Q?caf=E3?==", "", L""}, |
97 "", L""}, | |
98 // Extra token at the end of an encoded word | 99 // Extra token at the end of an encoded word |
99 {"attachment; filename==?iso88591?Q?caf=E3?=?", | 100 {"attachment; filename==?iso88591?Q?caf=E3?=?", "", L""}, |
100 "", L""}, | 101 {"attachment; filename==?iso88591?Q?caf=E3?=?=", "", L""}, |
101 {"attachment; filename==?iso88591?Q?caf=E3?=?=", | |
102 "", L""}, | |
103 // Incomplete hex-escaped chars | 102 // Incomplete hex-escaped chars |
104 {"attachment; filename==?windows-1252?Q?=63=61=E?=", | 103 {"attachment; filename==?windows-1252?Q?=63=61=E?=", "", L""}, |
105 "", L""}, | |
106 {"attachment; filename=%EC%98%88%EC%88%A", "", L""}, | 104 {"attachment; filename=%EC%98%88%EC%88%A", "", L""}, |
107 // %-escaped non-UTF-8 encoding is an "error" | 105 // %-escaped non-UTF-8 encoding is an "error" |
108 {"attachment; filename=%B7%DD%BD%D1.png", "", L""}, | 106 {"attachment; filename=%B7%DD%BD%D1.png", "", L""}, |
109 // Two RFC 2047 encoded words in a row without a space is an error. | 107 // Two RFC 2047 encoded words in a row without a space is an error. |
110 {"attachment; filename==?windows-1252?Q?caf=E3?=" | 108 {"attachment; filename==?windows-1252?Q?caf=E3?=" |
111 "=?iso-8859-7?b?4eIucG5nCg==?=", "", L""}, | 109 "=?iso-8859-7?b?4eIucG5nCg==?=", |
| 110 "", L""}, |
112 | 111 |
113 // RFC 5987 tests with Filename* : see http://tools.ietf.org/html/rfc5987 | 112 // RFC 5987 tests with Filename* : see http://tools.ietf.org/html/rfc5987 |
114 {"attachment; filename*=foo.html", "", L""}, | 113 {"attachment; filename*=foo.html", "", L""}, |
115 {"attachment; filename*=foo'.html", "", L""}, | 114 {"attachment; filename*=foo'.html", "", L""}, |
116 {"attachment; filename*=''foo'.html", "", L""}, | 115 {"attachment; filename*=''foo'.html", "", L""}, |
117 {"attachment; filename*=''foo.html'", "", L""}, | 116 {"attachment; filename*=''foo.html'", "", L""}, |
118 {"attachment; filename*=''f\"oo\".html'", "", L""}, | 117 {"attachment; filename*=''f\"oo\".html'", "", L""}, |
119 {"attachment; filename*=bogus_charset''foo.html'", | 118 {"attachment; filename*=bogus_charset''foo.html'", "", L""}, |
120 "", L""}, | |
121 {"attachment; filename*='en'foo.html'", "", L""}, | 119 {"attachment; filename*='en'foo.html'", "", L""}, |
122 {"attachment; filename*=iso-8859-1'en'foo.html", "", | 120 {"attachment; filename*=iso-8859-1'en'foo.html", "", L"foo.html"}, |
123 L"foo.html"}, | 121 {"attachment; filename*=utf-8'en'foo.html", "", L"foo.html"}, |
124 {"attachment; filename*=utf-8'en'foo.html", "", | |
125 L"foo.html"}, | |
126 // charset cannot be omitted. | 122 // charset cannot be omitted. |
127 {"attachment; filename*='es'f\xfa.html'", "", L""}, | 123 {"attachment; filename*='es'f\xfa.html'", "", L""}, |
128 // Non-ASCII bytes are not allowed. | 124 // Non-ASCII bytes are not allowed. |
129 {"attachment; filename*=iso-8859-1'es'f\xfa.html", "", | 125 {"attachment; filename*=iso-8859-1'es'f\xfa.html", "", L""}, |
130 L""}, | 126 {"attachment; filename*=utf-8'es'f\xce\xba.html", "", L""}, |
131 {"attachment; filename*=utf-8'es'f\xce\xba.html", "", | |
132 L""}, | |
133 // TODO(jshin): Space should be %-encoded, but currently, we allow | 127 // TODO(jshin): Space should be %-encoded, but currently, we allow |
134 // spaces. | 128 // spaces. |
135 {"inline; filename*=iso88591''cafe foo.png", "", | 129 {"inline; filename*=iso88591''cafe foo.png", "", L"cafe foo.png"}, |
136 L"cafe foo.png"}, | |
137 | 130 |
138 // Filename* tests converted from Q-encoded tests above. | 131 // Filename* tests converted from Q-encoded tests above. |
139 {"attachment; filename*=EUC-JP''%B7%DD%BD%D13%2Epng", | 132 {"attachment; filename*=EUC-JP''%B7%DD%BD%D13%2Epng", "", |
140 "", L"\x82b8\x8853" L"3.png"}, | 133 L"\x82b8\x8853" |
| 134 L"3.png"}, |
141 {"attachment; filename*=utf-8''" | 135 {"attachment; filename*=utf-8''" |
142 "%E8%8A%B8%E8%A1%93%203%2Epng", "", L"\x82b8\x8853 3.png"}, | 136 "%E8%8A%B8%E8%A1%93%203%2Epng", |
| 137 "", L"\x82b8\x8853 3.png"}, |
143 {"attachment; filename*=utf-8''%F0%90%8C%B0 3.png", "", | 138 {"attachment; filename*=utf-8''%F0%90%8C%B0 3.png", "", |
144 L"\U00010330 3.png"}, | 139 L"\U00010330 3.png"}, |
145 {"inline; filename*=Euc-Kr'ko'%BF%B9%BC%FA%2Epng", "", | 140 {"inline; filename*=Euc-Kr'ko'%BF%B9%BC%FA%2Epng", "", L"\xc608\xc220.png"}, |
146 L"\xc608\xc220.png"}, | 141 {"attachment; filename*=windows-1252''caf%E9.png", "", L"caf\x00e9.png"}, |
147 {"attachment; filename*=windows-1252''caf%E9.png", "", | |
148 L"caf\x00e9.png"}, | |
149 | 142 |
150 // Multiple filename, filename*, name parameters specified. | 143 // Multiple filename, filename*, name parameters specified. |
151 {"attachment; name=\"foo\"; filename=\"bar\"", "", L"bar"}, | 144 {"attachment; name=\"foo\"; filename=\"bar\"", "", L"bar"}, |
152 {"attachment; filename=\"bar\"; name=\"foo\"", "", L"bar"}, | 145 {"attachment; filename=\"bar\"; name=\"foo\"", "", L"bar"}, |
153 {"attachment; filename=\"bar\"; filename*=utf-8''baz", "", L"baz"}, | 146 {"attachment; filename=\"bar\"; filename*=utf-8''baz", "", L"baz"}, |
154 | 147 |
155 // http://greenbytes.de/tech/tc2231/ filename* test cases. | 148 // http://greenbytes.de/tech/tc2231/ filename* test cases. |
156 // attwithisofn2231iso | 149 // attwithisofn2231iso |
157 {"attachment; filename*=iso-8859-1''foo-%E4.html", "", | 150 {"attachment; filename*=iso-8859-1''foo-%E4.html", "", L"foo-\xe4.html"}, |
158 L"foo-\xe4.html"}, | |
159 // attwithfn2231utf8 | 151 // attwithfn2231utf8 |
160 {"attachment; filename*=" | 152 {"attachment; filename*=" |
161 "UTF-8''foo-%c3%a4-%e2%82%ac.html", "", L"foo-\xe4-\x20ac.html"}, | 153 "UTF-8''foo-%c3%a4-%e2%82%ac.html", |
| 154 "", L"foo-\xe4-\x20ac.html"}, |
162 // attwithfn2231noc : no encoding specified but UTF-8 is used. | 155 // attwithfn2231noc : no encoding specified but UTF-8 is used. |
163 {"attachment; filename*=''foo-%c3%a4-%e2%82%ac.html", | 156 {"attachment; filename*=''foo-%c3%a4-%e2%82%ac.html", "", L""}, |
164 "", L""}, | |
165 // attwithfn2231utf8comp | 157 // attwithfn2231utf8comp |
166 {"attachment; filename*=UTF-8''foo-a%cc%88.html", "", | 158 {"attachment; filename*=UTF-8''foo-a%cc%88.html", "", L"foo-\xe4.html"}, |
167 L"foo-\xe4.html"}, | |
168 #ifdef ICU_SHOULD_FAIL_CONVERSION_ON_INVALID_CHARACTER | 159 #ifdef ICU_SHOULD_FAIL_CONVERSION_ON_INVALID_CHARACTER |
169 // This does not work because we treat ISO-8859-1 synonymous with | 160 // This does not work because we treat ISO-8859-1 synonymous with |
170 // Windows-1252 per HTML5. For HTTP, in theory, we're not | 161 // Windows-1252 per HTML5. For HTTP, in theory, we're not |
171 // supposed to. | 162 // supposed to. |
172 // attwithfn2231utf8-bad | 163 // attwithfn2231utf8-bad |
173 {"attachment; filename*=" | 164 {"attachment; filename*=" |
174 "iso-8859-1''foo-%c3%a4-%e2%82%ac.html", "", L""}, | 165 "iso-8859-1''foo-%c3%a4-%e2%82%ac.html", |
| 166 "", L""}, |
175 #endif | 167 #endif |
176 // attwithfn2231ws1 | 168 // attwithfn2231ws1 |
177 {"attachment; filename *=UTF-8''foo-%c3%a4.html", "", | 169 {"attachment; filename *=UTF-8''foo-%c3%a4.html", "", L""}, |
178 L""}, | |
179 // attwithfn2231ws2 | 170 // attwithfn2231ws2 |
180 {"attachment; filename*= UTF-8''foo-%c3%a4.html", "", | 171 {"attachment; filename*= UTF-8''foo-%c3%a4.html", "", L"foo-\xe4.html"}, |
181 L"foo-\xe4.html"}, | |
182 // attwithfn2231ws3 | 172 // attwithfn2231ws3 |
183 {"attachment; filename* =UTF-8''foo-%c3%a4.html", "", | 173 {"attachment; filename* =UTF-8''foo-%c3%a4.html", "", L"foo-\xe4.html"}, |
184 L"foo-\xe4.html"}, | |
185 // attwithfn2231quot | 174 // attwithfn2231quot |
186 {"attachment; filename*=\"UTF-8''foo-%c3%a4.html\"", | 175 {"attachment; filename*=\"UTF-8''foo-%c3%a4.html\"", "", L""}, |
187 "", L""}, | |
188 // attfnboth | 176 // attfnboth |
189 {"attachment; filename=\"foo-ae.html\"; " | 177 {"attachment; filename=\"foo-ae.html\"; " |
190 "filename*=UTF-8''foo-%c3%a4.html", "", L"foo-\xe4.html"}, | 178 "filename*=UTF-8''foo-%c3%a4.html", |
| 179 "", L"foo-\xe4.html"}, |
191 // attfnboth2 | 180 // attfnboth2 |
192 {"attachment; filename*=UTF-8''foo-%c3%a4.html; " | 181 {"attachment; filename*=UTF-8''foo-%c3%a4.html; " |
193 "filename=\"foo-ae.html\"", "", L"foo-\xe4.html"}, | 182 "filename=\"foo-ae.html\"", |
| 183 "", L"foo-\xe4.html"}, |
194 // attnewandfn | 184 // attnewandfn |
195 {"attachment; foobar=x; filename=\"foo.html\"", "", | 185 {"attachment; foobar=x; filename=\"foo.html\"", "", L"foo.html"}, |
196 L"foo.html"}, | |
197 }; | 186 }; |
198 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 187 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
199 HttpContentDisposition header(tests[i].header, tests[i].referrer_charset); | 188 HttpContentDisposition header(tests[i].header, tests[i].referrer_charset); |
200 EXPECT_EQ(tests[i].expected, | 189 EXPECT_EQ(tests[i].expected, base::UTF8ToWide(header.filename())) |
201 base::UTF8ToWide(header.filename())) | |
202 << "Failed on input: " << tests[i].header; | 190 << "Failed on input: " << tests[i].header; |
203 } | 191 } |
204 } | 192 } |
205 | 193 |
206 // Test cases from http://greenbytes.de/tech/tc2231/ | 194 // Test cases from http://greenbytes.de/tech/tc2231/ |
207 TEST(HttpContentDispositionTest, tc2231) { | 195 TEST(HttpContentDispositionTest, tc2231) { |
208 const struct FileNameCDCase { | 196 const struct FileNameCDCase { |
209 const char* header; | 197 const char* header; |
210 net::HttpContentDisposition::Type expected_type; | 198 net::HttpContentDisposition::Type expected_type; |
211 const wchar_t* expected_filename; | 199 const wchar_t* expected_filename; |
212 } tests[] = { | 200 } tests[] = { |
213 // http://greenbytes.de/tech/tc2231/#inlonly | 201 // http://greenbytes.de/tech/tc2231/#inlonly |
214 { "inline", | 202 {"inline", net::HttpContentDisposition::INLINE, L""}, |
215 net::HttpContentDisposition::INLINE, | 203 // http://greenbytes.de/tech/tc2231/#inlonlyquoted |
216 L"" | 204 {"\"inline\"", net::HttpContentDisposition::INLINE, L""}, |
217 }, | 205 // http://greenbytes.de/tech/tc2231/#inlwithasciifilename |
218 // http://greenbytes.de/tech/tc2231/#inlonlyquoted | 206 {"inline; filename=\"foo.html\"", net::HttpContentDisposition::INLINE, |
219 { "\"inline\"", | 207 L"foo.html"}, |
220 net::HttpContentDisposition::INLINE, | 208 // http://greenbytes.de/tech/tc2231/#inlwithfnattach |
221 L"" | 209 {"inline; filename=\"Not an attachment!\"", |
222 }, | 210 net::HttpContentDisposition::INLINE, L"Not an attachment!"}, |
223 // http://greenbytes.de/tech/tc2231/#inlwithasciifilename | 211 // http://greenbytes.de/tech/tc2231/#inlwithasciifilenamepdf |
224 { "inline; filename=\"foo.html\"", | 212 {"inline; filename=\"foo.pdf\"", net::HttpContentDisposition::INLINE, |
225 net::HttpContentDisposition::INLINE, | 213 L"foo.pdf"}, |
226 L"foo.html" | 214 // http://greenbytes.de/tech/tc2231/#attonly |
227 }, | 215 {"attachment", net::HttpContentDisposition::ATTACHMENT, L""}, |
228 // http://greenbytes.de/tech/tc2231/#inlwithfnattach | 216 // http://greenbytes.de/tech/tc2231/#attonlyquoted |
229 { "inline; filename=\"Not an attachment!\"", | 217 {"\"attachment\"", net::HttpContentDisposition::INLINE, L""}, |
230 net::HttpContentDisposition::INLINE, | 218 // http://greenbytes.de/tech/tc2231/#attonly403 |
231 L"Not an attachment!" | 219 // TODO(abarth): This isn't testable in this unit test. |
232 }, | 220 // http://greenbytes.de/tech/tc2231/#attonlyucase |
233 // http://greenbytes.de/tech/tc2231/#inlwithasciifilenamepdf | 221 {"ATTACHMENT", net::HttpContentDisposition::ATTACHMENT, L""}, |
234 { "inline; filename=\"foo.pdf\"", | 222 // http://greenbytes.de/tech/tc2231/#attwithasciifilename |
235 net::HttpContentDisposition::INLINE, | 223 {"attachment; filename=\"foo.html\"", |
236 L"foo.pdf" | 224 net::HttpContentDisposition::ATTACHMENT, L"foo.html"}, |
237 }, | 225 // http://greenbytes.de/tech/tc2231/#attwithasciifnescapedchar |
238 // http://greenbytes.de/tech/tc2231/#attonly | 226 {"attachment; filename=\"f\\oo.html\"", |
239 { "attachment", | 227 net::HttpContentDisposition::ATTACHMENT, L"foo.html"}, |
240 net::HttpContentDisposition::ATTACHMENT, | 228 // http://greenbytes.de/tech/tc2231/#attwithasciifnescapedquote |
241 L"" | 229 {"attachment; filename=\"\\\"quoting\\\" tested.html\"", |
242 }, | 230 net::HttpContentDisposition::ATTACHMENT, L"\"quoting\" tested.html"}, |
243 // http://greenbytes.de/tech/tc2231/#attonlyquoted | 231 // http://greenbytes.de/tech/tc2231/#attwithquotedsemicolon |
244 { "\"attachment\"", | 232 {"attachment; filename=\"Here's a semicolon;.html\"", |
245 net::HttpContentDisposition::INLINE, | 233 net::HttpContentDisposition::ATTACHMENT, L"Here's a semicolon;.html"}, |
246 L"" | 234 // http://greenbytes.de/tech/tc2231/#attwithfilenameandextparam |
247 }, | 235 {"attachment; foo=\"bar\"; filename=\"foo.html\"", |
248 // http://greenbytes.de/tech/tc2231/#attonly403 | 236 net::HttpContentDisposition::ATTACHMENT, L"foo.html"}, |
249 // TODO(abarth): This isn't testable in this unit test. | 237 // http://greenbytes.de/tech/tc2231/#attwithfilenameandextparamescaped |
250 // http://greenbytes.de/tech/tc2231/#attonlyucase | 238 {"attachment; foo=\"\\\"\\\\\";filename=\"foo.html\"", |
251 { "ATTACHMENT", | 239 net::HttpContentDisposition::ATTACHMENT, L"foo.html"}, |
252 net::HttpContentDisposition::ATTACHMENT, | 240 // http://greenbytes.de/tech/tc2231/#attwithasciifilenameucase |
253 L"" | 241 {"attachment; FILENAME=\"foo.html\"", |
254 }, | 242 net::HttpContentDisposition::ATTACHMENT, L"foo.html"}, |
255 // http://greenbytes.de/tech/tc2231/#attwithasciifilename | 243 // http://greenbytes.de/tech/tc2231/#attwithasciifilenamenq |
256 { "attachment; filename=\"foo.html\"", | 244 {"attachment; filename=foo.html", |
257 net::HttpContentDisposition::ATTACHMENT, | 245 net::HttpContentDisposition::ATTACHMENT, L"foo.html"}, |
258 L"foo.html" | 246 // http://greenbytes.de/tech/tc2231/#attwithasciifilenamenqs |
259 }, | 247 // Note: tc2231 says we should fail to parse this header. |
260 // http://greenbytes.de/tech/tc2231/#attwithasciifnescapedchar | 248 {"attachment; filename=foo.html ;", |
261 { "attachment; filename=\"f\\oo.html\"", | 249 net::HttpContentDisposition::ATTACHMENT, L"foo.html"}, |
262 net::HttpContentDisposition::ATTACHMENT, | 250 // http://greenbytes.de/tech/tc2231/#attemptyparam |
263 L"foo.html" | 251 // Note: tc2231 says we should fail to parse this header. |
264 }, | 252 {"attachment; ;filename=foo", net::HttpContentDisposition::ATTACHMENT, |
265 // http://greenbytes.de/tech/tc2231/#attwithasciifnescapedquote | 253 L"foo"}, |
266 { "attachment; filename=\"\\\"quoting\\\" tested.html\"", | 254 // http://greenbytes.de/tech/tc2231/#attwithasciifilenamenqws |
267 net::HttpContentDisposition::ATTACHMENT, | 255 // Note: tc2231 says we should fail to parse this header. |
268 L"\"quoting\" tested.html" | 256 {"attachment; filename=foo bar.html", |
269 }, | 257 net::HttpContentDisposition::ATTACHMENT, L"foo bar.html"}, |
270 // http://greenbytes.de/tech/tc2231/#attwithquotedsemicolon | 258 // http://greenbytes.de/tech/tc2231/#attwithfntokensq |
271 { "attachment; filename=\"Here's a semicolon;.html\"", | 259 { |
272 net::HttpContentDisposition::ATTACHMENT, | 260 "attachment; filename='foo.bar'", |
273 L"Here's a semicolon;.html" | 261 net::HttpContentDisposition::ATTACHMENT, |
274 }, | 262 L"foo.bar" // Should be L"'foo.bar'" |
275 // http://greenbytes.de/tech/tc2231/#attwithfilenameandextparam | 263 }, |
276 { "attachment; foo=\"bar\"; filename=\"foo.html\"", | |
277 net::HttpContentDisposition::ATTACHMENT, | |
278 L"foo.html" | |
279 }, | |
280 // http://greenbytes.de/tech/tc2231/#attwithfilenameandextparamescaped | |
281 { "attachment; foo=\"\\\"\\\\\";filename=\"foo.html\"", | |
282 net::HttpContentDisposition::ATTACHMENT, | |
283 L"foo.html" | |
284 }, | |
285 // http://greenbytes.de/tech/tc2231/#attwithasciifilenameucase | |
286 { "attachment; FILENAME=\"foo.html\"", | |
287 net::HttpContentDisposition::ATTACHMENT, | |
288 L"foo.html" | |
289 }, | |
290 // http://greenbytes.de/tech/tc2231/#attwithasciifilenamenq | |
291 { "attachment; filename=foo.html", | |
292 net::HttpContentDisposition::ATTACHMENT, | |
293 L"foo.html" | |
294 }, | |
295 // http://greenbytes.de/tech/tc2231/#attwithasciifilenamenqs | |
296 // Note: tc2231 says we should fail to parse this header. | |
297 { "attachment; filename=foo.html ;", | |
298 net::HttpContentDisposition::ATTACHMENT, | |
299 L"foo.html" | |
300 }, | |
301 // http://greenbytes.de/tech/tc2231/#attemptyparam | |
302 // Note: tc2231 says we should fail to parse this header. | |
303 { "attachment; ;filename=foo", | |
304 net::HttpContentDisposition::ATTACHMENT, | |
305 L"foo" | |
306 }, | |
307 // http://greenbytes.de/tech/tc2231/#attwithasciifilenamenqws | |
308 // Note: tc2231 says we should fail to parse this header. | |
309 { "attachment; filename=foo bar.html", | |
310 net::HttpContentDisposition::ATTACHMENT, | |
311 L"foo bar.html" | |
312 }, | |
313 // http://greenbytes.de/tech/tc2231/#attwithfntokensq | |
314 { "attachment; filename='foo.bar'", | |
315 net::HttpContentDisposition::ATTACHMENT, | |
316 L"foo.bar" // Should be L"'foo.bar'" | |
317 }, | |
318 #ifdef ICU_SHOULD_FAIL_CONVERSION_ON_INVALID_CHARACTER | 264 #ifdef ICU_SHOULD_FAIL_CONVERSION_ON_INVALID_CHARACTER |
319 // http://greenbytes.de/tech/tc2231/#attwithisofnplain | 265 // http://greenbytes.de/tech/tc2231/#attwithisofnplain |
320 { "attachment; filename=\"foo-\xE4html\"", | 266 { |
321 net::HttpContentDisposition::ATTACHMENT, | 267 "attachment; filename=\"foo-\xE4html\"", |
322 L"" // Should be L"foo-\xE4.html" | 268 net::HttpContentDisposition::ATTACHMENT, |
323 }, | 269 L"" // Should be L"foo-\xE4.html" |
| 270 }, |
324 #endif | 271 #endif |
325 // http://greenbytes.de/tech/tc2231/#attwithutf8fnplain | 272 // http://greenbytes.de/tech/tc2231/#attwithutf8fnplain |
326 // Note: We'll UTF-8 decode the file name, even though tc2231 says not to. | 273 // Note: We'll UTF-8 decode the file name, even though tc2231 says not |
327 { "attachment; filename=\"foo-\xC3\xA4.html\"", | 274 // to. |
328 net::HttpContentDisposition::ATTACHMENT, | 275 {"attachment; filename=\"foo-\xC3\xA4.html\"", |
329 L"foo-\xE4.html" | 276 net::HttpContentDisposition::ATTACHMENT, L"foo-\xE4.html"}, |
330 }, | 277 // http://greenbytes.de/tech/tc2231/#attwithfnrawpctenca |
331 // http://greenbytes.de/tech/tc2231/#attwithfnrawpctenca | 278 { |
332 { "attachment; filename=\"foo-%41.html\"", | 279 "attachment; filename=\"foo-%41.html\"", |
333 net::HttpContentDisposition::ATTACHMENT, | 280 net::HttpContentDisposition::ATTACHMENT, |
334 L"foo-A.html" // Should be L"foo-%41.html" | 281 L"foo-A.html" // Should be L"foo-%41.html" |
335 }, | 282 }, |
336 // http://greenbytes.de/tech/tc2231/#attwithfnusingpct | 283 // http://greenbytes.de/tech/tc2231/#attwithfnusingpct |
337 { "attachment; filename=\"50%.html\"", | 284 {"attachment; filename=\"50%.html\"", |
338 net::HttpContentDisposition::ATTACHMENT, | 285 net::HttpContentDisposition::ATTACHMENT, L"50%.html"}, |
339 L"50%.html" | 286 // http://greenbytes.de/tech/tc2231/#attwithfnrawpctencaq |
340 }, | 287 { |
341 // http://greenbytes.de/tech/tc2231/#attwithfnrawpctencaq | 288 "attachment; filename=\"foo-%\\41.html\"", |
342 { "attachment; filename=\"foo-%\\41.html\"", | 289 net::HttpContentDisposition::ATTACHMENT, |
343 net::HttpContentDisposition::ATTACHMENT, | 290 L"foo-A.html" // Should be L"foo-%41.html" |
344 L"foo-A.html" // Should be L"foo-%41.html" | 291 }, |
345 }, | 292 // http://greenbytes.de/tech/tc2231/#attwithnamepct |
346 // http://greenbytes.de/tech/tc2231/#attwithnamepct | 293 { |
347 { "attachment; name=\"foo-%41.html\"", | 294 "attachment; name=\"foo-%41.html\"", |
348 net::HttpContentDisposition::ATTACHMENT, | 295 net::HttpContentDisposition::ATTACHMENT, |
349 L"foo-A.html" // Should be L"foo-%41.html" | 296 L"foo-A.html" // Should be L"foo-%41.html" |
350 }, | 297 }, |
351 #ifdef ICU_SHOULD_FAIL_CONVERSION_ON_INVALID_CHARACTER | 298 #ifdef ICU_SHOULD_FAIL_CONVERSION_ON_INVALID_CHARACTER |
352 // http://greenbytes.de/tech/tc2231/#attwithfilenamepctandiso | 299 // http://greenbytes.de/tech/tc2231/#attwithfilenamepctandiso |
353 { "attachment; filename=\"\xE4-%41.html\"", | 300 { |
354 net::HttpContentDisposition::ATTACHMENT, | 301 "attachment; filename=\"\xE4-%41.html\"", |
355 L"" // Should be L"\xE4-%41.htm" | 302 net::HttpContentDisposition::ATTACHMENT, |
356 }, | 303 L"" // Should be L"\xE4-%41.htm" |
| 304 }, |
357 #endif | 305 #endif |
358 // http://greenbytes.de/tech/tc2231/#attwithfnrawpctenclong | 306 // http://greenbytes.de/tech/tc2231/#attwithfnrawpctenclong |
359 { "attachment; filename=\"foo-%c3%a4-%e2%82%ac.html\"", | 307 { |
360 net::HttpContentDisposition::ATTACHMENT, | 308 "attachment; filename=\"foo-%c3%a4-%e2%82%ac.html\"", |
361 L"foo-\xE4-\u20AC.html" // Should be L"foo-%c3%a4-%e2%82%ac.html" | 309 net::HttpContentDisposition::ATTACHMENT, |
362 }, | 310 L"foo-\xE4-\u20AC.html" // Should be L"foo-%c3%a4-%e2%82%ac.html" |
363 // http://greenbytes.de/tech/tc2231/#attwithasciifilenamews1 | 311 }, |
364 { "attachment; filename =\"foo.html\"", | 312 // http://greenbytes.de/tech/tc2231/#attwithasciifilenamews1 |
365 net::HttpContentDisposition::ATTACHMENT, | 313 {"attachment; filename =\"foo.html\"", |
366 L"foo.html" | 314 net::HttpContentDisposition::ATTACHMENT, L"foo.html"}, |
367 }, | 315 // http://greenbytes.de/tech/tc2231/#attwith2filenames |
368 // http://greenbytes.de/tech/tc2231/#attwith2filenames | 316 // Note: tc2231 says we should fail to parse this header. |
369 // Note: tc2231 says we should fail to parse this header. | 317 {"attachment; filename=\"foo.html\"; filename=\"bar.html\"", |
370 { "attachment; filename=\"foo.html\"; filename=\"bar.html\"", | 318 net::HttpContentDisposition::ATTACHMENT, L"foo.html"}, |
371 net::HttpContentDisposition::ATTACHMENT, | 319 // http://greenbytes.de/tech/tc2231/#attfnbrokentoken |
372 L"foo.html" | 320 // Note: tc2231 says we should fail to parse this header. |
373 }, | 321 {"attachment; filename=foo[1](2).html", |
374 // http://greenbytes.de/tech/tc2231/#attfnbrokentoken | 322 net::HttpContentDisposition::ATTACHMENT, L"foo[1](2).html"}, |
375 // Note: tc2231 says we should fail to parse this header. | |
376 { "attachment; filename=foo[1](2).html", | |
377 net::HttpContentDisposition::ATTACHMENT, | |
378 L"foo[1](2).html" | |
379 }, | |
380 #ifdef ICU_SHOULD_FAIL_CONVERSION_ON_INVALID_CHARACTER | 323 #ifdef ICU_SHOULD_FAIL_CONVERSION_ON_INVALID_CHARACTER |
381 // http://greenbytes.de/tech/tc2231/#attfnbrokentokeniso | 324 // http://greenbytes.de/tech/tc2231/#attfnbrokentokeniso |
382 // Note: tc2231 says we should fail to parse this header. | 325 // Note: tc2231 says we should fail to parse this header. |
383 { "attachment; filename=foo-\xE4.html", | 326 {"attachment; filename=foo-\xE4.html", |
384 net::HttpContentDisposition::ATTACHMENT, | 327 net::HttpContentDisposition::ATTACHMENT, L""}, |
385 L"" | |
386 }, | |
387 #endif | 328 #endif |
388 // http://greenbytes.de/tech/tc2231/#attfnbrokentokenutf | 329 // http://greenbytes.de/tech/tc2231/#attfnbrokentokenutf |
389 // Note: tc2231 says we should fail to parse this header. | 330 // Note: tc2231 says we should fail to parse this header. |
390 { "attachment; filename=foo-\xC3\xA4.html", | 331 {"attachment; filename=foo-\xC3\xA4.html", |
391 net::HttpContentDisposition::ATTACHMENT, | 332 net::HttpContentDisposition::ATTACHMENT, L"foo-\xE4.html"}, |
392 L"foo-\xE4.html" | 333 // http://greenbytes.de/tech/tc2231/#attmissingdisposition |
393 }, | 334 // Note: tc2231 says we should fail to parse this header. |
394 // http://greenbytes.de/tech/tc2231/#attmissingdisposition | 335 {"filename=foo.html", net::HttpContentDisposition::INLINE, L"foo.html"}, |
395 // Note: tc2231 says we should fail to parse this header. | 336 // http://greenbytes.de/tech/tc2231/#attmissingdisposition2 |
396 { "filename=foo.html", | 337 // Note: tc2231 says we should fail to parse this header. |
397 net::HttpContentDisposition::INLINE, | 338 {"x=y; filename=foo.html", net::HttpContentDisposition::INLINE, |
398 L"foo.html" | 339 L"foo.html"}, |
399 }, | 340 // http://greenbytes.de/tech/tc2231/#attmissingdisposition3 |
400 // http://greenbytes.de/tech/tc2231/#attmissingdisposition2 | 341 // Note: tc2231 says we should fail to parse this header. |
401 // Note: tc2231 says we should fail to parse this header. | 342 { |
402 { "x=y; filename=foo.html", | 343 "\"foo; filename=bar;baz\"; filename=qux", |
403 net::HttpContentDisposition::INLINE, | 344 net::HttpContentDisposition::INLINE, |
404 L"foo.html" | 345 L"" // Firefox gets qux |
405 }, | 346 }, |
406 // http://greenbytes.de/tech/tc2231/#attmissingdisposition3 | 347 // http://greenbytes.de/tech/tc2231/#attmissingdisposition4 |
407 // Note: tc2231 says we should fail to parse this header. | 348 // Note: tc2231 says we should fail to parse this header. |
408 { "\"foo; filename=bar;baz\"; filename=qux", | 349 {"filename=foo.html, filename=bar.html", |
409 net::HttpContentDisposition::INLINE, | 350 net::HttpContentDisposition::INLINE, L"foo.html, filename=bar.html"}, |
410 L"" // Firefox gets qux | 351 // http://greenbytes.de/tech/tc2231/#emptydisposition |
411 }, | 352 // Note: tc2231 says we should fail to parse this header. |
412 // http://greenbytes.de/tech/tc2231/#attmissingdisposition4 | 353 {"; filename=foo.html", net::HttpContentDisposition::INLINE, |
413 // Note: tc2231 says we should fail to parse this header. | 354 L"foo.html"}, |
414 { "filename=foo.html, filename=bar.html", | 355 // http://greenbytes.de/tech/tc2231/#attandinline |
415 net::HttpContentDisposition::INLINE, | 356 // Note: tc2231 says we should fail to parse this header. |
416 L"foo.html, filename=bar.html" | 357 {"inline; attachment; filename=foo.html", |
417 }, | 358 net::HttpContentDisposition::INLINE, L""}, |
418 // http://greenbytes.de/tech/tc2231/#emptydisposition | 359 // http://greenbytes.de/tech/tc2231/#attandinline2 |
419 // Note: tc2231 says we should fail to parse this header. | 360 // Note: tc2231 says we should fail to parse this header. |
420 { "; filename=foo.html", | 361 {"attachment; inline; filename=foo.html", |
421 net::HttpContentDisposition::INLINE, | 362 net::HttpContentDisposition::ATTACHMENT, L""}, |
422 L"foo.html" | 363 // http://greenbytes.de/tech/tc2231/#attbrokenquotedfn |
423 }, | 364 // Note: tc2231 says we should fail to parse this header. |
424 // http://greenbytes.de/tech/tc2231/#attandinline | 365 {"attachment; filename=\"foo.html\".txt", |
425 // Note: tc2231 says we should fail to parse this header. | 366 net::HttpContentDisposition::ATTACHMENT, L"foo.html\".txt"}, |
426 { "inline; attachment; filename=foo.html", | 367 // http://greenbytes.de/tech/tc2231/#attbrokenquotedfn2 |
427 net::HttpContentDisposition::INLINE, | 368 // Note: tc2231 says we should fail to parse this header. |
428 L"" | 369 {"attachment; filename=\"bar", net::HttpContentDisposition::ATTACHMENT, |
429 }, | 370 L"bar"}, |
430 // http://greenbytes.de/tech/tc2231/#attandinline2 | 371 // http://greenbytes.de/tech/tc2231/#attbrokenquotedfn3 |
431 // Note: tc2231 says we should fail to parse this header. | 372 // Note: tc2231 says we should fail to parse this header. |
432 { "attachment; inline; filename=foo.html", | 373 {"attachment; filename=foo\"bar;baz\"qux", |
433 net::HttpContentDisposition::ATTACHMENT, | 374 net::HttpContentDisposition::ATTACHMENT, L"foo\"bar;baz\"qux"}, |
434 L"" | 375 // http://greenbytes.de/tech/tc2231/#attmultinstances |
435 }, | 376 // Note: tc2231 says we should fail to parse this header. |
436 // http://greenbytes.de/tech/tc2231/#attbrokenquotedfn | 377 {"attachment; filename=foo.html, attachment; filename=bar.html", |
437 // Note: tc2231 says we should fail to parse this header. | 378 net::HttpContentDisposition::ATTACHMENT, L"foo.html, attachment"}, |
438 { "attachment; filename=\"foo.html\".txt", | 379 // http://greenbytes.de/tech/tc2231/#attmissingdelim |
439 net::HttpContentDisposition::ATTACHMENT, | 380 {"attachment; foo=foo filename=bar", |
440 L"foo.html\".txt" | 381 net::HttpContentDisposition::ATTACHMENT, L""}, |
441 }, | 382 // http://greenbytes.de/tech/tc2231/#attreversed |
442 // http://greenbytes.de/tech/tc2231/#attbrokenquotedfn2 | 383 // Note: tc2231 says we should fail to parse this header. |
443 // Note: tc2231 says we should fail to parse this header. | 384 {"filename=foo.html; attachment", net::HttpContentDisposition::INLINE, |
444 { "attachment; filename=\"bar", | 385 L"foo.html"}, |
445 net::HttpContentDisposition::ATTACHMENT, | 386 // http://greenbytes.de/tech/tc2231/#attconfusedparam |
446 L"bar" | 387 {"attachment; xfilename=foo.html", |
447 }, | 388 net::HttpContentDisposition::ATTACHMENT, L""}, |
448 // http://greenbytes.de/tech/tc2231/#attbrokenquotedfn3 | 389 // http://greenbytes.de/tech/tc2231/#attabspath |
449 // Note: tc2231 says we should fail to parse this header. | 390 {"attachment; filename=\"/foo.html\"", |
450 { "attachment; filename=foo\"bar;baz\"qux", | 391 net::HttpContentDisposition::ATTACHMENT, L"/foo.html"}, |
451 net::HttpContentDisposition::ATTACHMENT, | 392 // http://greenbytes.de/tech/tc2231/#attabspathwin |
452 L"foo\"bar;baz\"qux" | 393 {"attachment; filename=\"\\\\foo.html\"", |
453 }, | 394 net::HttpContentDisposition::ATTACHMENT, L"\\foo.html"}, |
454 // http://greenbytes.de/tech/tc2231/#attmultinstances | 395 // http://greenbytes.de/tech/tc2231/#dispext |
455 // Note: tc2231 says we should fail to parse this header. | 396 {"foobar", net::HttpContentDisposition::ATTACHMENT, L""}, |
456 { "attachment; filename=foo.html, attachment; filename=bar.html", | 397 // http://greenbytes.de/tech/tc2231/#dispextbadfn |
457 net::HttpContentDisposition::ATTACHMENT, | 398 {"attachment; example=\"filename=example.txt\"", |
458 L"foo.html, attachment" | 399 net::HttpContentDisposition::ATTACHMENT, L""}, |
459 }, | 400 // http://greenbytes.de/tech/tc2231/#attnewandfn |
460 // http://greenbytes.de/tech/tc2231/#attmissingdelim | 401 {"attachment; foobar=x; filename=\"foo.html\"", |
461 { "attachment; foo=foo filename=bar", | 402 net::HttpContentDisposition::ATTACHMENT, L"foo.html"}, |
462 net::HttpContentDisposition::ATTACHMENT, | 403 // TODO(abarth): Add the filename* tests, but check |
463 L"" | 404 // HttpContentDispositionTest.Filename for overlap. |
464 }, | 405 // TODO(abarth): http://greenbytes.de/tech/tc2231/#attrfc2047token |
465 // http://greenbytes.de/tech/tc2231/#attreversed | 406 // TODO(abarth): http://greenbytes.de/tech/tc2231/#attrfc2047quoted |
466 // Note: tc2231 says we should fail to parse this header. | 407 }; |
467 { "filename=foo.html; attachment", | |
468 net::HttpContentDisposition::INLINE, | |
469 L"foo.html" | |
470 }, | |
471 // http://greenbytes.de/tech/tc2231/#attconfusedparam | |
472 { "attachment; xfilename=foo.html", | |
473 net::HttpContentDisposition::ATTACHMENT, | |
474 L"" | |
475 }, | |
476 // http://greenbytes.de/tech/tc2231/#attabspath | |
477 { "attachment; filename=\"/foo.html\"", | |
478 net::HttpContentDisposition::ATTACHMENT, | |
479 L"/foo.html" | |
480 }, | |
481 // http://greenbytes.de/tech/tc2231/#attabspathwin | |
482 { "attachment; filename=\"\\\\foo.html\"", | |
483 net::HttpContentDisposition::ATTACHMENT, | |
484 L"\\foo.html" | |
485 }, | |
486 // http://greenbytes.de/tech/tc2231/#dispext | |
487 { "foobar", | |
488 net::HttpContentDisposition::ATTACHMENT, | |
489 L"" | |
490 }, | |
491 // http://greenbytes.de/tech/tc2231/#dispextbadfn | |
492 { "attachment; example=\"filename=example.txt\"", | |
493 net::HttpContentDisposition::ATTACHMENT, | |
494 L"" | |
495 }, | |
496 // http://greenbytes.de/tech/tc2231/#attnewandfn | |
497 { "attachment; foobar=x; filename=\"foo.html\"", | |
498 net::HttpContentDisposition::ATTACHMENT, | |
499 L"foo.html" | |
500 }, | |
501 // TODO(abarth): Add the filename* tests, but check | |
502 // HttpContentDispositionTest.Filename for overlap. | |
503 // TODO(abarth): http://greenbytes.de/tech/tc2231/#attrfc2047token | |
504 // TODO(abarth): http://greenbytes.de/tech/tc2231/#attrfc2047quoted | |
505 }; | |
506 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 408 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
507 HttpContentDisposition header(tests[i].header, std::string()); | 409 HttpContentDisposition header(tests[i].header, std::string()); |
508 EXPECT_EQ(tests[i].expected_type, header.type()) | 410 EXPECT_EQ(tests[i].expected_type, header.type()) |
509 << "Failed on input: " << tests[i].header; | 411 << "Failed on input: " << tests[i].header; |
510 EXPECT_EQ(tests[i].expected_filename, base::UTF8ToWide(header.filename())) | 412 EXPECT_EQ(tests[i].expected_filename, base::UTF8ToWide(header.filename())) |
511 << "Failed on input: " << tests[i].header; | 413 << "Failed on input: " << tests[i].header; |
512 } | 414 } |
513 } | 415 } |
514 | 416 |
515 TEST(HttpContentDispositionTest, ParseResult) { | 417 TEST(HttpContentDispositionTest, ParseResult) { |
516 const struct ParseResultTestCase { | 418 const struct ParseResultTestCase { |
517 const char* header; | 419 const char* header; |
518 int expected_flags; | 420 int expected_flags; |
519 } kTestCases[] = { | 421 } kTestCases[] = { |
520 // Basic feature tests | 422 // Basic feature tests |
521 { "", HttpContentDisposition::INVALID }, | 423 {"", HttpContentDisposition::INVALID}, |
522 { "example=x", HttpContentDisposition::INVALID }, | 424 {"example=x", HttpContentDisposition::INVALID}, |
523 { "attachment; filename=", HttpContentDisposition::HAS_DISPOSITION_TYPE }, | 425 {"attachment; filename=", HttpContentDisposition::HAS_DISPOSITION_TYPE}, |
524 { "attachment; name=", HttpContentDisposition::HAS_DISPOSITION_TYPE }, | 426 {"attachment; name=", HttpContentDisposition::HAS_DISPOSITION_TYPE}, |
525 { "attachment; filename*=", HttpContentDisposition::HAS_DISPOSITION_TYPE }, | 427 {"attachment; filename*=", |
526 { "attachment; filename==?utf-8?Q?\?=", | 428 HttpContentDisposition::HAS_DISPOSITION_TYPE}, |
527 HttpContentDisposition::HAS_DISPOSITION_TYPE }, | 429 {"attachment; filename==?utf-8?Q?\?=", |
528 { "filename=x", HttpContentDisposition::HAS_FILENAME }, | 430 HttpContentDisposition::HAS_DISPOSITION_TYPE}, |
529 { "example; filename=x", | 431 {"filename=x", HttpContentDisposition::HAS_FILENAME}, |
530 HttpContentDisposition::HAS_DISPOSITION_TYPE | | 432 {"example; filename=x", |
531 HttpContentDisposition::HAS_UNKNOWN_DISPOSITION_TYPE | | 433 HttpContentDisposition::HAS_DISPOSITION_TYPE | |
532 HttpContentDisposition::HAS_FILENAME}, | 434 HttpContentDisposition::HAS_UNKNOWN_DISPOSITION_TYPE | |
533 { "attachment; filename=x", | 435 HttpContentDisposition::HAS_FILENAME}, |
534 HttpContentDisposition::HAS_DISPOSITION_TYPE | | 436 {"attachment; filename=x", |
535 HttpContentDisposition::HAS_FILENAME }, | 437 HttpContentDisposition::HAS_DISPOSITION_TYPE | |
536 { "attachment; filename=x; name=y", | 438 HttpContentDisposition::HAS_FILENAME}, |
537 HttpContentDisposition::HAS_DISPOSITION_TYPE | | 439 {"attachment; filename=x; name=y", |
538 HttpContentDisposition::HAS_FILENAME | | 440 HttpContentDisposition::HAS_DISPOSITION_TYPE | |
539 HttpContentDisposition::HAS_NAME }, | 441 HttpContentDisposition::HAS_FILENAME | |
540 { "attachment; name=y; filename*=utf-8''foo; name=x", | 442 HttpContentDisposition::HAS_NAME}, |
541 HttpContentDisposition::HAS_DISPOSITION_TYPE | | 443 {"attachment; name=y; filename*=utf-8''foo; name=x", |
542 HttpContentDisposition::HAS_EXT_FILENAME | | 444 HttpContentDisposition::HAS_DISPOSITION_TYPE | |
543 HttpContentDisposition::HAS_NAME }, | 445 HttpContentDisposition::HAS_EXT_FILENAME | |
| 446 HttpContentDisposition::HAS_NAME}, |
544 | 447 |
545 // Feature tests for 'filename' attribute. | 448 // Feature tests for 'filename' attribute. |
546 { "filename=foo\xcc\x88", | 449 {"filename=foo\xcc\x88", |
547 HttpContentDisposition::HAS_FILENAME | | 450 HttpContentDisposition::HAS_FILENAME | |
548 HttpContentDisposition::HAS_NON_ASCII_STRINGS }, | 451 HttpContentDisposition::HAS_NON_ASCII_STRINGS}, |
549 { "filename=foo%cc%88", | 452 {"filename=foo%cc%88", |
550 HttpContentDisposition::HAS_FILENAME | | 453 HttpContentDisposition::HAS_FILENAME | |
551 HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS }, | 454 HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS}, |
552 { "filename==?utf-8?Q?foo?=", | 455 {"filename==?utf-8?Q?foo?=", |
553 HttpContentDisposition::HAS_FILENAME | | 456 HttpContentDisposition::HAS_FILENAME | |
554 HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS }, | 457 HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS}, |
555 { "filename=\"=?utf-8?Q?foo?=\"", | 458 {"filename=\"=?utf-8?Q?foo?=\"", |
556 HttpContentDisposition::HAS_FILENAME | | 459 HttpContentDisposition::HAS_FILENAME | |
557 HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS }, | 460 HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS}, |
558 { "filename==?utf-8?Q?foo?", HttpContentDisposition::INVALID }, | 461 {"filename==?utf-8?Q?foo?", HttpContentDisposition::INVALID}, |
559 { "name=foo\xcc\x88", | 462 {"name=foo\xcc\x88", HttpContentDisposition::HAS_NAME}, |
560 HttpContentDisposition::HAS_NAME }, | |
561 | 463 |
562 // Shouldn't set |has_non_ascii_strings| based on 'name' attribute. | 464 // Shouldn't set |has_non_ascii_strings| based on 'name' attribute. |
563 { "filename=x; name=foo\xcc\x88", | 465 {"filename=x; name=foo\xcc\x88", HttpContentDisposition::HAS_FILENAME | |
564 HttpContentDisposition::HAS_FILENAME | | 466 HttpContentDisposition::HAS_NAME}, |
565 HttpContentDisposition::HAS_NAME }, | 467 {"filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?=", |
566 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?=", | 468 HttpContentDisposition::HAS_FILENAME | |
567 HttpContentDisposition::HAS_FILENAME | | 469 HttpContentDisposition::HAS_NON_ASCII_STRINGS | |
568 HttpContentDisposition::HAS_NON_ASCII_STRINGS | | 470 HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS | |
569 HttpContentDisposition::HAS_PERCENT_ENCODED_STRINGS | | 471 HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS}, |
570 HttpContentDisposition::HAS_RFC2047_ENCODED_STRINGS }, | |
571 | 472 |
572 // If 'filename' attribute is invalid, should set any flags based on it. | 473 // If 'filename' attribute is invalid, should set any flags based on it. |
573 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?", | 474 {"filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?", |
574 HttpContentDisposition::INVALID }, | 475 HttpContentDisposition::INVALID}, |
575 { "filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?; name=x", | 476 {"filename=foo\xcc\x88 foo%cc%88 =?utf-8?Q?foo?; name=x", |
576 HttpContentDisposition::HAS_NAME }, | 477 HttpContentDisposition::HAS_NAME}, |
577 }; | 478 }; |
578 | 479 |
579 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 480 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
580 const ParseResultTestCase& test_case = kTestCases[i]; | 481 const ParseResultTestCase& test_case = kTestCases[i]; |
581 HttpContentDisposition content_disposition(test_case.header, "utf-8"); | 482 HttpContentDisposition content_disposition(test_case.header, "utf-8"); |
582 int result = content_disposition.parse_result_flags(); | 483 int result = content_disposition.parse_result_flags(); |
583 | 484 |
584 SCOPED_TRACE(testing::Message() << "Test case " << i | 485 SCOPED_TRACE(testing::Message() << "Test case " << i << " with header " |
585 << " with header " << test_case.header); | 486 << test_case.header); |
586 EXPECT_EQ(test_case.expected_flags, result); | 487 EXPECT_EQ(test_case.expected_flags, result); |
587 } | 488 } |
588 } | 489 } |
589 | 490 |
590 } // namespace net | 491 } // namespace net |
OLD | NEW |