Index: pkg/http_server/lib/src/http_multipart_form_data_impl.dart |
diff --git a/sdk/lib/io/http_multipart_form_data_impl.dart b/pkg/http_server/lib/src/http_multipart_form_data_impl.dart |
similarity index 73% |
rename from sdk/lib/io/http_multipart_form_data_impl.dart |
rename to pkg/http_server/lib/src/http_multipart_form_data_impl.dart |
index b2279541cc428a274aae780bac501a5354967c1a..cc8d154a7c14b45ec0e976b020f8b28f43f1cd85 100644 |
--- a/sdk/lib/io/http_multipart_form_data_impl.dart |
+++ b/pkg/http_server/lib/src/http_multipart_form_data_impl.dart |
@@ -2,7 +2,7 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-part of dart.io; |
+part of http_server; |
class _HttpMultipartFormData extends Stream implements HttpMultipartFormData { |
@@ -41,7 +41,7 @@ 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(); |
return [out]; |
@@ -100,3 +100,41 @@ class _HttpMultipartFormData extends Stream implements HttpMultipartFormData { |
} |
} |
+ |
+// Decode a string with HTTP entities. Returns null if the string ends in the |
+// middle of a http entity. |
+// TODO(ajohnsen): Provide in dart:io? |
+String _decodeHttpEntityString(String input) { |
+ int amp = input.lastIndexOf('&'); |
+ if (amp < 0) return input; |
+ int end = input.lastIndexOf(';'); |
Bill Hesse
2013/07/03 11:30:27
or indexOf(';', amp)
Anders Johnsen
2013/07/12 10:45:57
This is gone.
|
+ 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(); |
+} |