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

Unified Diff: runtime/bin/http_utils.dart

Issue 10382148: Revert "Fix URL decoding in HTTP library" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 | « no previous file | runtime/bin/io.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/http_utils.dart
diff --git a/runtime/bin/http_utils.dart b/runtime/bin/http_utils.dart
index 5414510bf38601c73da6c0e366a890841cb1932d..3b120fd53ee2992bfd1bf3e54715b9b1379c9090 100644
--- a/runtime/bin/http_utils.dart
+++ b/runtime/bin/http_utils.dart
@@ -4,46 +4,35 @@
class _HttpUtils {
static String decodeUrlEncodedString(String urlEncoded) {
- // First check the string for any encoding.
- int index = 0;
- bool encoded = false;
- while (!encoded && index < urlEncoded.length) {
- encoded = urlEncoded[index] == "+" || urlEncoded[index] == "%";
- index++;
+ void invalidEscape() {
+ // TODO(sgjesse): Handle the error.
}
- if (!encoded) return urlEncoded;
- index--;
- // Start decoding from the first encoded character.
- List<int> bytes = new List<int>();
- for (int i = 0; i < index; i++) bytes.add(urlEncoded.charCodeAt(i));
- for (int i = index; i < urlEncoded.length; i++) {
- if (urlEncoded[i] == "+") {
- bytes.add(32);
- } else if (urlEncoded[i] == "%") {
- if (urlEncoded.length - i < 2) {
- throw new HttpException("Invalid URL encoding");
- }
- int byte = 0;
- for (int j = 0; j < 2; j++) {
- var charCode = urlEncoded.charCodeAt(i + j + 1);
- if (0x30 <= charCode && charCode <= 0x39) {
- byte = byte * 16 + charCode - 0x30;
- } else if (0x41 <= charCode && charCode <= 0x46) {
- byte = byte * 16 + charCode - 0x37;
- } else if (0x61 <= charCode && charCode <= 0x66) {
- byte = byte * 16 + charCode - 0x57;
+ StringBuffer result = new StringBuffer();
+ for (int ii = 0; urlEncoded.length > ii; ++ii) {
Mads Ager (google) 2012/05/14 10:46:08 Why 'ii' instead of 'i'?
+ if ('+' == urlEncoded[ii]) {
+ result.add(' ');
+ } else if ('%' == urlEncoded[ii] &&
+ urlEncoded.length - 2 > ii) {
+ try {
+ int charCode =
+ Math.parseInt('0x' + urlEncoded.substring(ii + 1, ii + 3));
+ if (charCode <= 0x7f) {
+ result.add(new String.fromCharCodes([charCode]));
+ ii += 2;
} else {
- throw new HttpException("Invalid URL encoding");
+ invalidEscape();
+ return '';
}
+ } catch (BadNumberFormatException ignored) {
+ invalidEscape();
+ return '';
}
- bytes.add(byte);
- i += 2;
} else {
- bytes.add(urlEncoded.charCodeAt(i));
+ result.add(urlEncoded[ii]);
}
}
- return decodeUtf8(bytes);
+ return result.toString();
}
static Map<String, String> splitQueryString(String queryString) {
« no previous file with comments | « no previous file | runtime/bin/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698