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

Unified Diff: sdk/lib/core/uri.dart

Issue 23904004: Accept IPv6 addresses in Uri.http and Uri.https, and correctly nest IPv6 addresses in '[' and ']'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/uri.dart
diff --git a/sdk/lib/core/uri.dart b/sdk/lib/core/uri.dart
index 30057f1132e5fc0952ffa3172755189f76a71116..88f6e113a3f28d850ab367342b181636de3bc196 100644
--- a/sdk/lib/core/uri.dart
+++ b/sdk/lib/core/uri.dart
@@ -153,9 +153,9 @@ class Uri {
*
* The fragment component is set through [fragment].
*/
- Uri({scheme,
+ Uri({String scheme,
this.userInfo: "",
- this.host: "",
+ String host: "",
port: 0,
String path,
Iterable<String> pathSegments,
@@ -163,6 +163,7 @@ class Uri {
Map<String, String> queryParameters,
fragment: ""}) :
scheme = _makeScheme(scheme),
+ host = _makeHost(host),
query = _makeQuery(query, queryParameters),
fragment = _makeFragment(fragment) {
// Perform scheme specific normalization.
@@ -237,12 +238,29 @@ class Uri {
break;
}
}
+ var hostEnd = null;
floitsch 2013/09/09 13:32:21 That's how I would write it. var hostEnd = hostSt
Anders Johnsen 2013/09/10 11:13:23 Done.
+ var portStart = hostStart;
+ if (authority.codeUnitAt(hostStart) == _LEFT_BRACKET) {
+ // IPv6 host.
+ for (int i = hostStart; i < authority.length; i++) {
+ if (authority.codeUnitAt(i) == _RIGHT_BRACKET) {
+ hostEnd = i;
+ break;
+ }
+ }
+ if (hostEnd == null) {
+ throw new FormatException("Invalid IPv6 host entry.");
+ }
+ hostEnd++;
+ portStart = hostEnd;
+ }
// Split host and port.
bool hasPort = false;
- for (int i = hostStart; i < authority.length; i++) {
+ for (int i = portStart; i < authority.length; i++) {
if (authority.codeUnitAt(i) == _COLON) {
hasPort = true;
floitsch 2013/09/09 13:32:21 you set hasPort to true, but if the host is empty
Anders Johnsen 2013/09/10 11:13:23 Done.
- host = authority.substring(hostStart, i);
+ if (hostEnd == null) hostEnd = i;
+ host = authority.substring(hostStart, hostEnd);
if (!host.isEmpty) {
floitsch 2013/09/09 13:32:21 if you just check hostStart != hostEnd you don't n
Anders Johnsen 2013/09/10 11:13:23 Done.
var portString = authority.substring(i + 1);
if (portString.isNotEmpty) port = int.parse(portString);
floitsch 2013/09/09 13:32:21 is this intended behavior? (an authority with ":"
Anders Johnsen 2013/09/10 11:13:23 Done.
@@ -251,7 +269,7 @@ class Uri {
}
}
if (!hasPort) {
- host = hasUserInfo ? authority.substring(hostStart) : authority;
+ host = authority.substring(hostStart, hostEnd);
}
return new Uri(scheme: scheme,
@@ -474,6 +492,23 @@ class Uri {
return _queryParameters;
}
+ static String _makeHost(String host) {
+ if (host.isEmpty) return host;
+ if (host.codeUnitAt(0) == _LEFT_BRACKET) return host;
floitsch 2013/09/09 13:32:21 I would prefer a more sophisticated host-parser: d
Anders Johnsen 2013/09/10 11:13:23 Done.
+ for (int i = 0; i < host.length; i++) {
+ if (host.codeUnitAt(i) == _COLON) {
+ var buffer = new StringBuffer();
+ buffer.writeCharCode(_LEFT_BRACKET);
+ buffer.write(host);
+ if (host.codeUnitAt(host.length - 1) != _RIGHT_BRACKET) {
+ buffer.writeCharCode(_RIGHT_BRACKET);
+ }
+ return buffer.toString();
+ }
+ }
+ return host;
+ }
+
static String _makeScheme(String scheme) {
bool isSchemeLowerCharacter(int ch) {
return ch < 128 &&
@@ -1164,7 +1199,9 @@ class Uri {
static const int _UPPER_CASE_A = 0x41;
static const int _UPPER_CASE_F = 0x46;
static const int _UPPER_CASE_Z = 0x5A;
+ static const int _LEFT_BRACKET = 0x5B;
static const int _BACKSLASH = 0x5C;
+ static const int _RIGHT_BRACKET = 0x5D;
static const int _LOWER_CASE_A = 0x61;
static const int _LOWER_CASE_F = 0x66;
static const int _LOWER_CASE_Z = 0x7A;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698