Chromium Code Reviews| 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 library uriTest; | 5 library uriTest; |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 testUri(String uriText, bool isAbsolute) { | 10 testUri(String uriText, bool isAbsolute) { |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 748 Expect.listEquals(["43", "38"], params["y"]); | 748 Expect.listEquals(["43", "38"], params["y"]); |
| 749 | 749 |
| 750 // Test replacing with empty strings. | 750 // Test replacing with empty strings. |
| 751 uri = Uri.parse("s://a:1/b/c?d#e"); | 751 uri = Uri.parse("s://a:1/b/c?d#e"); |
| 752 Expect.equals("s://a:1/b/c?d#", uri.replace(fragment: "").toString()); | 752 Expect.equals("s://a:1/b/c?d#", uri.replace(fragment: "").toString()); |
| 753 Expect.equals("s://a:1/b/c?#e", uri.replace(query: "").toString()); | 753 Expect.equals("s://a:1/b/c?#e", uri.replace(query: "").toString()); |
| 754 Expect.equals("s://a:1?d#e", uri.replace(path: "").toString()); | 754 Expect.equals("s://a:1?d#e", uri.replace(path: "").toString()); |
| 755 Expect.equals("s://:1/b/c?d#e", uri.replace(host: "").toString()); | 755 Expect.equals("s://:1/b/c?d#e", uri.replace(host: "").toString()); |
| 756 } | 756 } |
| 757 | 757 |
| 758 void testRegression28359() { | |
| 759 var uri = new Uri(path: "//"); | |
| 760 // This is an invalid path for a URI reference with no authority | |
| 761 // since it looks like an authority. | |
| 762 // Normalized to have an authority. | |
| 763 Expect.equals("////", "$uri"); | |
| 764 Expect.equals("//", uri.path); | |
| 765 Expect.isTrue(uri.hasAuthority, "$uri has authority"); | |
| 766 | |
| 767 uri = new Uri(path: "file:///wat"); | |
| 768 // This is an invalid pat for a URI reference with no authority or scheme | |
|
floitsch
2017/01/12 16:05:49
path
Lasse Reichstein Nielsen
2017/01/16 08:17:23
Done.
| |
| 769 // since the path looks like it starts with a scheme. | |
| 770 // Normalized by escaping the ":". | |
| 771 Expect.equals("file%3A///wat", uri.path); | |
| 772 Expect.equals("file%3A///wat", "$uri"); | |
| 773 Expect.isFalse(uri.hasAuthority); | |
| 774 Expect.isFalse(uri.hasScheme); | |
| 775 } | |
| 776 | |
| 758 main() { | 777 main() { |
| 759 testUri("http:", true); | 778 testUri("http:", true); |
| 760 testUri("file:///", true); | 779 testUri("file:///", true); |
| 761 testUri("file", false); | 780 testUri("file", false); |
| 762 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); | 781 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); |
| 763 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", | 782 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", |
| 764 false); | 783 false); |
| 765 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", | 784 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", |
| 766 new Uri( | 785 new Uri( |
| 767 scheme: "http", | 786 scheme: "http", |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 914 | 933 |
| 915 // Invalid URI - : and @ is swapped, port ("host") should be numeric. | 934 // Invalid URI - : and @ is swapped, port ("host") should be numeric. |
| 916 Expect.throws( | 935 Expect.throws( |
| 917 () => Uri.parse("file://user@password:host/path"), | 936 () => Uri.parse("file://user@password:host/path"), |
| 918 (e) => e is FormatException); | 937 (e) => e is FormatException); |
| 919 | 938 |
| 920 testValidCharacters(); | 939 testValidCharacters(); |
| 921 testInvalidUrls(); | 940 testInvalidUrls(); |
| 922 testNormalization(); | 941 testNormalization(); |
| 923 testReplace(); | 942 testReplace(); |
| 943 testRegression28359(); | |
| 924 } | 944 } |
| 925 | 945 |
| 926 String dump(Uri uri) { | 946 String dump(Uri uri) { |
| 927 return "URI: $uri\n" | 947 return "URI: $uri\n" |
| 928 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" | 948 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" |
| 929 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" | 949 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" |
| 930 " Host: ${uri.host} #${uri.host.length}\n" | 950 " Host: ${uri.host} #${uri.host.length}\n" |
| 931 " Port: ${uri.port}\n" | 951 " Port: ${uri.port}\n" |
| 932 " Path: ${uri.path} #${uri.path.length}\n" | 952 " Path: ${uri.path} #${uri.path.length}\n" |
| 933 " Query: ${uri.query} #${uri.query.length}\n" | 953 " Query: ${uri.query} #${uri.query.length}\n" |
| 934 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; | 954 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; |
| 935 } | 955 } |
| OLD | NEW |