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

Side by Side Diff: sdk/lib/core/uri.dart

Issue 15854003: Fix some bugs in the Uri class (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/corelib/uri_query_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * A parsed URI, as specified by RFC-3986, http://tools.ietf.org/html/rfc3986. 8 * A parsed URI, as specified by RFC-3986, http://tools.ietf.org/html/rfc3986.
9 */ 9 */
10 class Uri { 10 class Uri {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 /* 176 /*
177 * Returns the URI query split into a map according to the rules 177 * Returns the URI query split into a map according to the rules
178 * specified for FORM post in the HTML 4.01 specification. Each key 178 * specified for FORM post in the HTML 4.01 specification. Each key
179 * and value in the returned map have been decoded. If there is no 179 * and value in the returned map have been decoded. If there is no
180 * query the empty map will be returned. 180 * query the empty map will be returned.
181 */ 181 */
182 Map<String, String> get queryParameters { 182 Map<String, String> get queryParameters {
183 return query.split("&").fold({}, (map, element) { 183 return query.split("&").fold({}, (map, element) {
184 int index = element.indexOf("="); 184 int index = element.indexOf("=");
185 if (index == -1) { 185 if (index == -1) {
186 if (!element.isEmpty) map[element] = ""; 186 if (!element.isEmpty) map[decodeQueryComponent(element)] = "";
187 } else if (index != 0) { 187 } else if (index != 0) {
188 var key = element.substring(0, index); 188 var key = element.substring(0, index);
189 var value = element.substring(index + 1); 189 var value = element.substring(index + 1);
190 map[Uri.decodeQueryComponent(key)] = decodeQueryComponent(value); 190 map[Uri.decodeQueryComponent(key)] = decodeQueryComponent(value);
191 } 191 }
192 return map; 192 return map;
193 }); 193 });
194 } 194 }
195 195
196 static String _makeScheme(String scheme) { 196 static String _makeScheme(String scheme) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 303 }
304 } 304 }
305 return byte; 305 return byte;
306 } 306 }
307 307
308 // Start building the normalized component string. 308 // Start building the normalized component string.
309 StringBuffer result; 309 StringBuffer result;
310 int length = component.length; 310 int length = component.length;
311 int index = 0; 311 int index = 0;
312 int prevIndex = 0; 312 int prevIndex = 0;
313
314 // Copy a part of the component string to the result.
315 fillResult() {
Lasse Reichstein Nielsen 2013/06/03 07:56:47 void return type. Makes it more obvious that this
Søren Gjesse 2013/06/03 09:35:41 Done.
316 if (result == null) {
317 assert(prevIndex == 0);
318 result = new StringBuffer(component.substring(prevIndex, index));
319 } else {
320 result.write(component.substring(prevIndex, index));
321 }
322 }
323
313 while (index < length) { 324 while (index < length) {
314 325
315 // Copy a part of the component string to the result.
316 fillResult() {
317 if (result == null) {
318 assert(prevIndex == 0);
319 result = new StringBuffer(component.substring(prevIndex, index));
320 } else {
321 result.write(component.substring(prevIndex, index));
322 }
323 }
324
325 // Normalize percent encoding to uppercase and don't encode 326 // Normalize percent encoding to uppercase and don't encode
326 // unreserved characters. 327 // unreserved characters.
327 if (component.codeUnitAt(index) == _PERCENT) { 328 if (component.codeUnitAt(index) == _PERCENT) {
328 if (length < index + 2) { 329 if (length < index + 2) {
329 throw new ArgumentError( 330 throw new ArgumentError(
330 "Invalid percent-encoding in URI component: $component"); 331 "Invalid percent-encoding in URI component: $component");
331 } 332 }
332 333
333 var codeUnit1 = component.codeUnitAt(index + 1); 334 var codeUnit1 = component.codeUnitAt(index + 1);
334 var codeUnit2 = component.codeUnitAt(index + 2); 335 var codeUnit2 = component.codeUnitAt(index + 2);
(...skipping 11 matching lines...) Expand all
346 result.writeCharCode(normalizeHexDigit(index + 1)); 347 result.writeCharCode(normalizeHexDigit(index + 1));
347 result.writeCharCode(normalizeHexDigit(index + 2)); 348 result.writeCharCode(normalizeHexDigit(index + 2));
348 } 349 }
349 index += 3; 350 index += 3;
350 prevIndex = index; 351 prevIndex = index;
351 } 352 }
352 } else { 353 } else {
353 index++; 354 index++;
354 } 355 }
355 } 356 }
357 if (result != null && prevIndex != index) fillResult();
356 assert(index == length); 358 assert(index == length);
357 359
358 if (result == null) return component; 360 if (result == null) return component;
359 return result.toString(); 361 return result.toString();
360 } 362 }
361 363
362 static String _emptyIfNull(String val) => val != null ? val : ''; 364 static String _emptyIfNull(String val) => val != null ? val : '';
363 365
364 static int _parseIntOrZero(String val) { 366 static int _parseIntOrZero(String val) {
365 if (val != null && val != '') { 367 if (val != null && val != '') {
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 0xafff, // 0x30 - 0x3f 1111111111110101 939 0xafff, // 0x30 - 0x3f 1111111111110101
938 // @ABCDEFGHIJKLMNO 940 // @ABCDEFGHIJKLMNO
939 0xffff, // 0x40 - 0x4f 1111111111111111 941 0xffff, // 0x40 - 0x4f 1111111111111111
940 // PQRSTUVWXYZ _ 942 // PQRSTUVWXYZ _
941 0x87ff, // 0x50 - 0x5f 1111111111100001 943 0x87ff, // 0x50 - 0x5f 1111111111100001
942 // abcdefghijklmno 944 // abcdefghijklmno
943 0xfffe, // 0x60 - 0x6f 0111111111111111 945 0xfffe, // 0x60 - 0x6f 0111111111111111
944 // pqrstuvwxyz ~ 946 // pqrstuvwxyz ~
945 0x47ff]; // 0x70 - 0x7f 1111111111100010 947 0x47ff]; // 0x70 - 0x7f 1111111111100010
946 } 948 }
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/uri_query_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698