Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a | 
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. | 
| 4 | 4 | 
| 5 library multipart_test; | 5 library multipart_test; | 
| 6 | 6 | 
| 7 import 'dart:async'; | 7 import 'dart:async'; | 
| 8 import 'dart:convert'; | 8 import 'dart:convert'; | 
| 9 import 'dart:io'; | 9 import 'dart:io'; | 
| 10 | 10 | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 --{{boundary}}-- | 86 --{{boundary}}-- | 
| 87 ''')); | 87 ''')); | 
| 88 }); | 88 }); | 
| 89 | 89 | 
| 90 test('with a unicode field name', () { | 90 test('with a unicode field name', () { | 
| 91 var request = new http.MultipartRequest('POST', dummyUrl); | 91 var request = new http.MultipartRequest('POST', dummyUrl); | 
| 92 request.fields['fïēld'] = 'value'; | 92 request.fields['fïēld'] = 'value'; | 
| 93 | 93 | 
| 94 expect(request, bodyMatches(''' | 94 expect(request, bodyMatches(''' | 
| 95 --{{boundary}} | 95 --{{boundary}} | 
| 96 content-disposition: form-data; name="f%C3%AF%C4%93ld" | 96 content-disposition: form-data; name="fïēld" | 
| 97 | 97 | 
| 98 value | 98 value | 
| 99 --{{boundary}}-- | 99 --{{boundary}}-- | 
| 100 ''')); | |
| 101 }); | |
| 102 | |
| 103 test('with a field name with newlines', () { | |
| 104 var request = new http.MultipartRequest('POST', dummyUrl); | |
| 105 request.fields['foo\nbar\rbaz\r\nbang'] = 'value'; | |
| 106 | |
| 107 expect(request, bodyMatches(''' | |
| 108 --{{boundary}} | |
| 109 content-disposition: form-data; name="foo%0D%0Abar%0D%0Abaz%0D%0Abang" | |
| 110 | |
| 111 value | |
| 112 --{{boundary}}-- | |
| 113 ''')); | |
| 114 }); | |
| 115 | |
| 116 test('with a field name with a quote', () { | |
| 117 var request = new http.MultipartRequest('POST', dummyUrl); | |
| 118 request.fields['foo"bar'] = 'value'; | |
| 119 | |
| 120 expect(request, bodyMatches(''' | |
| 121 --{{boundary}} | |
| 122 content-disposition: form-data; name="foo%22bar" | |
| 
 
Bob Nystrom
2014/04/01 19:45:26
Is it worth also testing that a single quote *isn'
 
nweiz
2014/04/02 01:09:44
I don't think so. There's nothing special about a
 
 | |
| 123 | |
| 124 value | |
| 125 --{{boundary}}-- | |
| 100 ''')); | 126 ''')); | 
| 101 }); | 127 }); | 
| 102 | 128 | 
| 103 test('with a unicode field value', () { | 129 test('with a unicode field value', () { | 
| 104 var request = new http.MultipartRequest('POST', dummyUrl); | 130 var request = new http.MultipartRequest('POST', dummyUrl); | 
| 105 request.fields['field'] = 'vⱥlūe'; | 131 request.fields['field'] = 'vⱥlūe'; | 
| 106 | 132 | 
| 107 expect(request, bodyMatches(''' | 133 expect(request, bodyMatches(''' | 
| 108 --{{boundary}} | 134 --{{boundary}} | 
| 109 content-disposition: form-data; name="field" | 135 content-disposition: form-data; name="field" | 
| 110 content-type: text/plain; charset=utf-8 | 136 content-type: text/plain; charset=utf-8 | 
| 111 | 137 | 
| 112 vⱥlūe | 138 vⱥlūe | 
| 113 --{{boundary}}-- | 139 --{{boundary}}-- | 
| 114 ''')); | 140 ''')); | 
| 115 }); | 141 }); | 
| 116 | 142 | 
| 117 test('with a unicode filename', () { | 143 test('with a unicode filename', () { | 
| 118 var request = new http.MultipartRequest('POST', dummyUrl); | 144 var request = new http.MultipartRequest('POST', dummyUrl); | 
| 119 request.files.add(new http.MultipartFile.fromString('file', 'contents', | 145 request.files.add(new http.MultipartFile.fromString('file', 'contents', | 
| 120 filename: 'fïlēname.txt')); | 146 filename: 'fïlēname.txt')); | 
| 121 | 147 | 
| 122 expect(request, bodyMatches(''' | 148 expect(request, bodyMatches(''' | 
| 123 --{{boundary}} | 149 --{{boundary}} | 
| 124 content-type: text/plain; charset=utf-8 | 150 content-type: text/plain; charset=utf-8 | 
| 125 content-disposition: form-data; name="file"; filename="f%C3%AFl%C4%93nam e.txt" | 151 content-disposition: form-data; name="file"; filename="fïlēname.txt" | 
| 126 | 152 | 
| 127 contents | 153 contents | 
| 128 --{{boundary}}-- | 154 --{{boundary}}-- | 
| 155 ''')); | |
| 156 }); | |
| 157 | |
| 158 test('with a filename with newlines', () { | |
| 159 var request = new http.MultipartRequest('POST', dummyUrl); | |
| 160 request.files.add(new http.MultipartFile.fromString('file', 'contents', | |
| 161 filename: 'foo\nbar\rbaz\r\nbang')); | |
| 162 | |
| 163 expect(request, bodyMatches(''' | |
| 164 --{{boundary}} | |
| 165 content-type: text/plain; charset=utf-8 | |
| 166 content-disposition: form-data; name="file"; filename="foo%0D%0Abar%0D%0 Abaz%0D%0Abang" | |
| 167 | |
| 168 contents | |
| 169 --{{boundary}}-- | |
| 170 ''')); | |
| 171 }); | |
| 172 | |
| 173 test('with a filename with a quote', () { | |
| 174 var request = new http.MultipartRequest('POST', dummyUrl); | |
| 175 request.files.add(new http.MultipartFile.fromString('file', 'contents', | |
| 176 filename: 'foo"bar')); | |
| 177 | |
| 178 expect(request, bodyMatches(''' | |
| 179 --{{boundary}} | |
| 180 content-type: text/plain; charset=utf-8 | |
| 181 content-disposition: form-data; name="file"; filename="foo%22bar" | |
| 182 | |
| 183 contents | |
| 184 --{{boundary}}-- | |
| 129 ''')); | 185 ''')); | 
| 130 }); | 186 }); | 
| 131 | 187 | 
| 132 test('with a string file with a content-type but no charset', () { | 188 test('with a string file with a content-type but no charset', () { | 
| 133 var request = new http.MultipartRequest('POST', dummyUrl); | 189 var request = new http.MultipartRequest('POST', dummyUrl); | 
| 134 var file = new http.MultipartFile.fromString('file', '{"hello": "world"}', | 190 var file = new http.MultipartFile.fromString('file', '{"hello": "world"}', | 
| 135 contentType: new ContentType('application', 'json')); | 191 contentType: new ContentType('application', 'json')); | 
| 136 request.files.add(file); | 192 request.files.add(file); | 
| 137 | 193 | 
| 138 expect(request, bodyMatches(''' | 194 expect(request, bodyMatches(''' | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 content-type: application/octet-stream | 291 content-type: application/octet-stream | 
| 236 content-disposition: form-data; name="file"; filename="test-file" | 292 content-disposition: form-data; name="file"; filename="test-file" | 
| 237 | 293 | 
| 238 hello | 294 hello | 
| 239 --{{boundary}}-- | 295 --{{boundary}}-- | 
| 240 ''')); | 296 ''')); | 
| 241 }), completes); | 297 }), completes); | 
| 242 }); | 298 }); | 
| 243 }); | 299 }); | 
| 244 } | 300 } | 
| OLD | NEW |