Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(597)

Unified Diff: sdk/lib/io/http_multipart_form_data_impl.dart

Issue 18576006: Remove _HttpUtils from dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated comments and add encoding tests. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/http_headers.dart ('k') | sdk/lib/io/http_utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/http_multipart_form_data_impl.dart
diff --git a/sdk/lib/io/http_multipart_form_data_impl.dart b/sdk/lib/io/http_multipart_form_data_impl.dart
index b2279541cc428a274aae780bac501a5354967c1a..8531a9522d7e4d5c838d2a35517e559303cab148 100644
--- a/sdk/lib/io/http_multipart_form_data_impl.dart
+++ b/sdk/lib/io/http_multipart_form_data_impl.dart
@@ -41,9 +41,9 @@ class _HttpMultipartFormData extends Stream implements HttpMultipartFormData {
.transform(new StringDecoder(encoding))
.expand((data) {
buffer.write(data);
- var out = _HttpUtils.decodeHttpEntityString(buffer.toString());
+ var out = _decodeHttpEntityString(buffer.toString());
if (out != null) {
- buffer = new StringBuffer();
+ buffer.clear();
return [out];
}
return const [];
@@ -98,5 +98,42 @@ class _HttpMultipartFormData extends Stream implements HttpMultipartFormData {
String value(String name) {
return _mimeMultipart.headers[name];
}
+
+ // Decode a string with HTTP entities. Returns null if the string ends in the
+ // middle of a http entity.
+ static String _decodeHttpEntityString(String input) {
+ int amp = input.lastIndexOf('&');
+ if (amp < 0) return input;
+ int end = input.lastIndexOf(';');
+ if (end < amp) return null;
+
+ var buffer = new StringBuffer();
+ int offset = 0;
+
+ parse(amp, end) {
+ switch (input[amp + 1]) {
+ case '#':
+ if (input[amp + 2] == 'x') {
+ buffer.writeCharCode(
+ int.parse(input.substring(amp + 3, end), radix: 16));
+ } else {
+ buffer.writeCharCode(int.parse(input.substring(amp + 2, end)));
+ }
+ break;
+
+ default:
+ throw new HttpException('Unhandled HTTP entity token');
+ }
+ }
+
+ while ((amp = input.indexOf('&', offset)) >= 0) {
+ buffer.write(input.substring(offset, amp));
+ int end = input.indexOf(';', amp);
+ parse(amp, end);
+ offset = end + 1;
+ }
+ buffer.write(input.substring(offset));
+ return buffer.toString();
+ }
}
« no previous file with comments | « sdk/lib/io/http_headers.dart ('k') | sdk/lib/io/http_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698