OLD | NEW |
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, such as a URL. | 8 * A parsed URI, such as a URL. |
9 * | 9 * |
10 * **See also:** | 10 * **See also:** |
11 * | 11 * |
12 * * [URIs][uris] in the [library tour][libtour] | 12 * * [URIs][uris] in the [library tour][libtour] |
13 * * [RFC-3986](http://tools.ietf.org/html/rfc3986) | 13 * * [RFC-3986](http://tools.ietf.org/html/rfc3986) |
14 * | 14 * |
15 * [uris]: http://www.dartlang.org/docs/dart-up-and-running/contents/ch03.html#c
h03-uri | 15 * [uris]: https://www.dartlang.org/docs/dart-up-and-running/ch03.html#uris |
16 * [libtour]: http://www.dartlang.org/docs/dart-up-and-running/contents/ch03.htm
l | 16 * [libtour]: https://www.dartlang.org/docs/dart-up-and-running/contents/ch03.ht
ml |
17 */ | 17 */ |
18 class Uri { | 18 class Uri { |
19 // The host name of the URI. | 19 // The host name of the URI. |
20 // Set to `null` if there is no authority in a URI. | 20 // Set to `null` if there is no authority in a URI. |
21 final String _host; | 21 final String _host; |
22 // The port. Set to null if there is no port. Normalized to null if | 22 // The port. Set to null if there is no port. Normalized to null if |
23 // the port is the default port for the scheme. | 23 // the port is the default port for the scheme. |
24 // Set to the value of the default port if an empty port was supplied. | 24 // Set to the value of the default port if an empty port was supplied. |
25 int _port; | 25 int _port; |
26 // The path. Always non-null. | 26 // The path. Always non-null. |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 pathToSplit == "" ? const<String>[] | 1013 pathToSplit == "" ? const<String>[] |
1014 : pathToSplit.split("/") | 1014 : pathToSplit.split("/") |
1015 .map(Uri.decodeComponent) | 1015 .map(Uri.decodeComponent) |
1016 .toList(growable: false)); | 1016 .toList(growable: false)); |
1017 } | 1017 } |
1018 return _pathSegments; | 1018 return _pathSegments; |
1019 } | 1019 } |
1020 | 1020 |
1021 /** | 1021 /** |
1022 * Returns the URI query split into a map according to the rules | 1022 * Returns the URI query split into a map according to the rules |
1023 * specified for FORM post in the [HTML 4.01 specification section 17.13.4] | 1023 * specified for FORM post in the [HTML 4.01 specification section |
1024 * (http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4 | 1024 * 17.13.4](http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4 "HTM
L 4.01 section 17.13.4"). |
1025 * "HTML 4.01 section 17.13.4"). Each key and value in the returned map | 1025 * Each key and value in the returned map has been decoded. If there is no |
1026 * has been decoded. If there is no query the empty map is returned. | 1026 * query the empty map is returned. |
1027 * | 1027 * |
1028 * Keys in the query string that have no value are mapped to the | 1028 * Keys in the query string that have no value are mapped to the |
1029 * empty string. | 1029 * empty string. |
1030 * | 1030 * |
1031 * The returned map is unmodifiable and will throw [UnsupportedError] on any | 1031 * The returned map is unmodifiable and will throw [UnsupportedError] on any |
1032 * calls that would mutate it. | 1032 * calls that would mutate it. |
1033 */ | 1033 */ |
1034 Map<String, String> get queryParameters { | 1034 Map<String, String> get queryParameters { |
1035 if (_queryParameters == null) { | 1035 if (_queryParameters == null) { |
1036 _queryParameters = new UnmodifiableMapView(splitQueryString(query)); | 1036 _queryParameters = new UnmodifiableMapView(splitQueryString(query)); |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 */ | 1582 */ |
1583 Uri resolve(String reference) { | 1583 Uri resolve(String reference) { |
1584 return resolveUri(Uri.parse(reference)); | 1584 return resolveUri(Uri.parse(reference)); |
1585 } | 1585 } |
1586 | 1586 |
1587 /** | 1587 /** |
1588 * Resolve [reference] as an URI relative to `this`. | 1588 * Resolve [reference] as an URI relative to `this`. |
1589 * | 1589 * |
1590 * Returns the resolved URI. | 1590 * Returns the resolved URI. |
1591 * | 1591 * |
1592 * The algorithm "Transform Reference" for resolving a reference is | 1592 * The algorithm "Transform Reference" for resolving a reference is described |
1593 * described in [RFC-3986 Section 5] | 1593 * in [RFC-3986 Section 5](http://tools.ietf.org/html/rfc3986#section-5 "RFC-1
123"). |
1594 * (http://tools.ietf.org/html/rfc3986#section-5 "RFC-1123"). | |
1595 * | 1594 * |
1596 * Updated to handle the case where the base URI is just a relative path - | 1595 * Updated to handle the case where the base URI is just a relative path - |
1597 * that is: when it has no scheme or authority and the path does not start | 1596 * that is: when it has no scheme or authority and the path does not start |
1598 * with a slash. | 1597 * with a slash. |
1599 * In that case, the paths are combined without removing leading "..", and | 1598 * In that case, the paths are combined without removing leading "..", and |
1600 * an empty path is not converted to "/". | 1599 * an empty path is not converted to "/". |
1601 */ | 1600 */ |
1602 Uri resolveUri(Uri reference) { | 1601 Uri resolveUri(Uri reference) { |
1603 // From RFC 3986. | 1602 // From RFC 3986. |
1604 String targetScheme; | 1603 String targetScheme; |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2032 * the decoded characters could be reserved characters. In most | 2031 * the decoded characters could be reserved characters. In most |
2033 * cases an encoded URI should be parsed into components using | 2032 * cases an encoded URI should be parsed into components using |
2034 * [Uri.parse] before decoding the separate components. | 2033 * [Uri.parse] before decoding the separate components. |
2035 */ | 2034 */ |
2036 static String decodeFull(String uri) { | 2035 static String decodeFull(String uri) { |
2037 return _uriDecode(uri); | 2036 return _uriDecode(uri); |
2038 } | 2037 } |
2039 | 2038 |
2040 /** | 2039 /** |
2041 * Returns the [query] split into a map according to the rules | 2040 * Returns the [query] split into a map according to the rules |
2042 * specified for FORM post in the | 2041 * specified for FORM post in the [HTML 4.01 specification section |
2043 * [HTML 4.01 specification section 17.13.4] | 2042 * 17.13.4](http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4 "HTM
L 4.01 section 17.13.4"). |
2044 * (http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4 | 2043 * Each key and value in the returned map has been decoded. If the [query] |
2045 * "HTML 4.01 section 17.13.4"). Each key and value in the returned | |
2046 * map has been decoded. If the [query] | |
2047 * is the empty string an empty map is returned. | 2044 * is the empty string an empty map is returned. |
2048 * | 2045 * |
2049 * Keys in the query string that have no value are mapped to the | 2046 * Keys in the query string that have no value are mapped to the |
2050 * empty string. | 2047 * empty string. |
2051 * | 2048 * |
2052 * Each query component will be decoded using [encoding]. The default encoding | 2049 * Each query component will be decoded using [encoding]. The default encoding |
2053 * is UTF-8. | 2050 * is UTF-8. |
2054 */ | 2051 */ |
2055 static Map<String, String> splitQueryString(String query, | 2052 static Map<String, String> splitQueryString(String query, |
2056 {Encoding encoding: UTF8}) { | 2053 {Encoding encoding: UTF8}) { |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2591 0xafff, // 0x30 - 0x3f 1111111111110101 | 2588 0xafff, // 0x30 - 0x3f 1111111111110101 |
2592 // @ABCDEFGHIJKLMNO | 2589 // @ABCDEFGHIJKLMNO |
2593 0xffff, // 0x40 - 0x4f 1111111111111111 | 2590 0xffff, // 0x40 - 0x4f 1111111111111111 |
2594 // PQRSTUVWXYZ _ | 2591 // PQRSTUVWXYZ _ |
2595 0x87ff, // 0x50 - 0x5f 1111111111100001 | 2592 0x87ff, // 0x50 - 0x5f 1111111111100001 |
2596 // abcdefghijklmno | 2593 // abcdefghijklmno |
2597 0xfffe, // 0x60 - 0x6f 0111111111111111 | 2594 0xfffe, // 0x60 - 0x6f 0111111111111111 |
2598 // pqrstuvwxyz ~ | 2595 // pqrstuvwxyz ~ |
2599 0x47ff]; // 0x70 - 0x7f 1111111111100010 | 2596 0x47ff]; // 0x70 - 0x7f 1111111111100010 |
2600 } | 2597 } |
OLD | NEW |