Index: sdk/lib/uri/uri.dart |
diff --git a/sdk/lib/uri/uri.dart b/sdk/lib/uri/uri.dart |
index 640ce3d0c7a32798ef2d019c322825be88896cdd..fe3ad5a7530f81d95e513923e98a1d18a84799eb 100644 |
--- a/sdk/lib/uri/uri.dart |
+++ b/sdk/lib/uri/uri.dart |
@@ -34,7 +34,8 @@ class Uri { |
Uri._fromMatch(Match m) : |
this.fromComponents(scheme: _emptyIfNull(m[_COMPONENT_SCHEME]), |
userInfo: _emptyIfNull(m[_COMPONENT_USER_INFO]), |
- domain: _emptyIfNull(m[_COMPONENT_DOMAIN]), |
+ domain: _eitherOf( |
+ m[_COMPONENT_DOMAIN], m[_COMPONENT_DOMAIN_IPV6]), |
port: _parseIntOrZero(m[_COMPONENT_PORT]), |
path: _emptyIfNull(m[_COMPONENT_PATH]), |
query: _emptyIfNull(m[_COMPONENT_QUERY_DATA]), |
@@ -60,6 +61,12 @@ class Uri { |
} |
} |
+ static String _eitherOf(String val1, String val2) { |
+ if (val1 != null) return val1; |
+ if (val2 != null) return val2; |
+ return ''; |
+ } |
+ |
// NOTE: This code was ported from: closure-library/closure/goog/uri/utils.js |
static final RegExp _splitRe = new RegExp( |
'^' |
@@ -70,13 +77,17 @@ class Uri { |
':)?' |
'(?://' |
'(?:([^/?#]*)@)?' // userInfo |
- '([\\w\\d\\-\\u0100-\\uffff.%]*)' |
+ '(?:' |
+ '([\\w\\d\\-\\u0100-\\uffff.%]*)|' |
// domain - restrict to letters, |
// digits, dashes, dots, percent |
// escapes, and unicode characters. |
+ '\\[([A-Fa-f0-9:.]*)\\])' |
+ // IPv6 domain - restrict to hex, |
+ // dot and colon. |
'(?::([0-9]+))?' // port |
')?' |
- '([^?#]+)?' // path |
+ '([^?#\\[]+)?' // path |
'(?:\\?([^#]*))?' // query |
'(?:#(.*))?' // fragment |
'\$'); |
@@ -84,10 +95,11 @@ class Uri { |
static const _COMPONENT_SCHEME = 1; |
static const _COMPONENT_USER_INFO = 2; |
static const _COMPONENT_DOMAIN = 3; |
- static const _COMPONENT_PORT = 4; |
- static const _COMPONENT_PATH = 5; |
- static const _COMPONENT_QUERY_DATA = 6; |
- static const _COMPONENT_FRAGMENT = 7; |
+ static const _COMPONENT_DOMAIN_IPV6 = 4; |
+ static const _COMPONENT_PORT = 5; |
+ static const _COMPONENT_PATH = 6; |
+ static const _COMPONENT_QUERY_DATA = 7; |
+ static const _COMPONENT_FRAGMENT = 8; |
/** |
* Returns `true` if the URI is absolute. |
@@ -222,7 +234,8 @@ class Uri { |
if (hasAuthority || (scheme == "file")) { |
sb.write("//"); |
_addIfNonEmpty(sb, userInfo, userInfo, "@"); |
- sb.write(domain == null ? "null" : domain); |
+ sb.write(domain == null ? "null" : |
+ domain.contains(':') ? '[$domain]' : domain); |
if (port != 0) { |
sb.write(":"); |
sb.write(port.toString()); |