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

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

Issue 23766030: Return the correct port from Uri, when port is 0 and scheme is either http or https. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix test. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/co19/co19-co19.status » ('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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 return _host.substring(1, _host.length - 1); 56 return _host.substring(1, _host.length - 1);
57 } 57 }
58 return _host; 58 return _host;
59 } 59 }
60 60
61 /** 61 /**
62 * Returns the port part of the authority component. 62 * Returns the port part of the authority component.
63 * 63 *
64 * Returns 0 if there is no port in the authority component. 64 * Returns 0 if there is no port in the authority component.
65 */ 65 */
66 int get port => _port; 66 int get port {
67 if (_port == 0) {
68 if (scheme == "http") return 80;
69 if (scheme == "https") return 443;
70 }
71 return _port;
72 }
67 73
68 /** 74 /**
69 * Returns the path component. 75 * Returns the path component.
70 * 76 *
71 * The returned path is encoded. To get direct access to the decoded 77 * The returned path is encoded. To get direct access to the decoded
72 * path use [pathSegments]. 78 * path use [pathSegments].
73 * 79 *
74 * Returns the empty string if there is no path component. 80 * Returns the empty string if there is no path component.
75 */ 81 */
76 String get path => _path; 82 String get path => _path;
(...skipping 23 matching lines...) Expand all
100 * Cache the computed return value of [queryParameters]. 106 * Cache the computed return value of [queryParameters].
101 */ 107 */
102 Map<String, String> _queryParameters; 108 Map<String, String> _queryParameters;
103 109
104 /** 110 /**
105 * Creates a new URI object by parsing a URI string. 111 * Creates a new URI object by parsing a URI string.
106 */ 112 */
107 static Uri parse(String uri) => new Uri._fromMatch(_splitRe.firstMatch(uri)); 113 static Uri parse(String uri) => new Uri._fromMatch(_splitRe.firstMatch(uri));
108 114
109 Uri._fromMatch(Match m) : 115 Uri._fromMatch(Match m) :
110 this(scheme: _emptyIfNull(m[_COMPONENT_SCHEME]), 116 this(scheme: _makeScheme(_emptyIfNull(m[_COMPONENT_SCHEME])),
111 userInfo: _emptyIfNull(m[_COMPONENT_USER_INFO]), 117 userInfo: _emptyIfNull(m[_COMPONENT_USER_INFO]),
112 host: _eitherOf( 118 host: _eitherOf(
113 m[_COMPONENT_HOST], m[_COMPONENT_HOST_IPV6]), 119 m[_COMPONENT_HOST], m[_COMPONENT_HOST_IPV6]),
114 port: _parseIntOrZero(m[_COMPONENT_PORT]), 120 port: _parseIntOrZero(m[_COMPONENT_PORT]),
115 path: _emptyIfNull(m[_COMPONENT_PATH]), 121 path: _emptyIfNull(m[_COMPONENT_PATH]),
116 query: _emptyIfNull(m[_COMPONENT_QUERY_DATA]), 122 query: _emptyIfNull(m[_COMPONENT_QUERY_DATA]),
117 fragment: _emptyIfNull(m[_COMPONENT_FRAGMENT])); 123 fragment: _emptyIfNull(m[_COMPONENT_FRAGMENT]));
118 124
119 /** 125 /**
120 * Creates a new URI from its components. 126 * Creates a new URI from its components.
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 static String _eitherOf(String val1, String val2) { 709 static String _eitherOf(String val1, String val2) {
704 if (val1 != null) return val1; 710 if (val1 != null) return val1;
705 if (val2 != null) return val2; 711 if (val2 != null) return val2;
706 return ''; 712 return '';
707 } 713 }
708 714
709 // NOTE: This code was ported from: closure-library/closure/goog/uri/utils.js 715 // NOTE: This code was ported from: closure-library/closure/goog/uri/utils.js
710 static final RegExp _splitRe = new RegExp( 716 static final RegExp _splitRe = new RegExp(
711 '^' 717 '^'
712 '(?:' 718 '(?:'
713 '([^:/?#.]+)' // scheme - ignore special characters 719 '([^:/?#]+)' // scheme - ignore special characters
Søren Gjesse 2013/09/12 13:03:14 Re-align comment.
Anders Johnsen 2013/09/12 13:25:23 Done.
714 // used by other URL parts such as :, 720 // used by other URL parts such as :,
715 // ?, /, #, and . 721 // ?, /, #, and .
716 ':)?' 722 ':)?'
717 '(?://' 723 '(?://'
718 '(?:([^/?#]*)@)?' // userInfo 724 '(?:([^/?#]*)@)?' // userInfo
719 '(?:' 725 '(?:'
720 r'([\w\d\-\u0100-\uffff.%]*)' 726 r'([\w\d\-\u0100-\uffff.%]*)'
721 // host - restrict to letters, 727 // host - restrict to letters,
722 // digits, dashes, dots, percent 728 // digits, dashes, dots, percent
723 // escapes, and unicode characters. 729 // escapes, and unicode characters.
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 * See: http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin 874 * See: http://www.w3.org/TR/2011/WD-html5-20110405/origin-0.html#origin
869 */ 875 */
870 String get origin { 876 String get origin {
871 if (scheme == "" || _host == null || _host == "") { 877 if (scheme == "" || _host == null || _host == "") {
872 throw new StateError("Cannot use origin without a scheme: $this"); 878 throw new StateError("Cannot use origin without a scheme: $this");
873 } 879 }
874 if (scheme != "http" && scheme != "https") { 880 if (scheme != "http" && scheme != "https") {
875 throw new StateError( 881 throw new StateError(
876 "Origin is only applicable schemes http and https: $this"); 882 "Origin is only applicable schemes http and https: $this");
877 } 883 }
878 if (port == 0) return "$scheme://$_host"; 884 if (_port == 0) return "$scheme://$_host";
879 return "$scheme://$_host:$port"; 885 return "$scheme://$_host:$_port";
880 } 886 }
881 887
882 /** 888 /**
883 * Returns the file path from a file URI. 889 * Returns the file path from a file URI.
884 * 890 *
885 * The returned path has either Windows or non-Windows 891 * The returned path has either Windows or non-Windows
886 * semantics. 892 * semantics.
887 * 893 *
888 * For non-Windows semantics the slash ("/") is used to separate 894 * For non-Windows semantics the slash ("/") is used to separate
889 * path segments. 895 * path segments.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 } 1007 }
1002 1008
1003 bool get _isPathAbsolute { 1009 bool get _isPathAbsolute {
1004 if (path == null || path.isEmpty) return false; 1010 if (path == null || path.isEmpty) return false;
1005 return path.startsWith('/'); 1011 return path.startsWith('/');
1006 } 1012 }
1007 1013
1008 void _writeAuthority(StringSink ss) { 1014 void _writeAuthority(StringSink ss) {
1009 _addIfNonEmpty(ss, userInfo, userInfo, "@"); 1015 _addIfNonEmpty(ss, userInfo, userInfo, "@");
1010 ss.write(_host == null ? "null" : _host); 1016 ss.write(_host == null ? "null" : _host);
1011 if (port != 0) { 1017 if (_port != 0) {
1012 ss.write(":"); 1018 ss.write(":");
1013 ss.write(port.toString()); 1019 ss.write(_port.toString());
1014 } 1020 }
1015 } 1021 }
1016 1022
1017 String toString() { 1023 String toString() {
1018 StringBuffer sb = new StringBuffer(); 1024 StringBuffer sb = new StringBuffer();
1019 _addIfNonEmpty(sb, scheme, scheme, ':'); 1025 _addIfNonEmpty(sb, scheme, scheme, ':');
1020 if (hasAuthority || (scheme == "file")) { 1026 if (hasAuthority || (scheme == "file")) {
1021 sb.write("//"); 1027 sb.write("//");
1022 _writeAuthority(sb); 1028 _writeAuthority(sb);
1023 } 1029 }
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 void clear() { 1646 void clear() {
1641 throw new UnsupportedError("Cannot modify an unmodifiable map"); 1647 throw new UnsupportedError("Cannot modify an unmodifiable map");
1642 } 1648 }
1643 void forEach(void f(K key, V value)) => _map.forEach(f); 1649 void forEach(void f(K key, V value)) => _map.forEach(f);
1644 Iterable<K> get keys => _map.keys; 1650 Iterable<K> get keys => _map.keys;
1645 Iterable<V> get values => _map.values; 1651 Iterable<V> get values => _map.values;
1646 int get length => _map.length; 1652 int get length => _map.length;
1647 bool get isEmpty => _map.isEmpty; 1653 bool get isEmpty => _map.isEmpty;
1648 bool get isNotEmpty => _map.isNotEmpty; 1654 bool get isNotEmpty => _map.isNotEmpty;
1649 } 1655 }
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-co19.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698