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

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

Issue 14753005: Enable parsing of IPv6 form addresse (see rfc2373 and rfc2732). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 | tests/lib/uri/uri_ipv6_test.dart » ('j') | tests/lib/uri/uri_ipv6_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « no previous file | tests/lib/uri/uri_ipv6_test.dart » ('j') | tests/lib/uri/uri_ipv6_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698