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

Side by Side Diff: tests/corelib/uri_test.dart

Issue 2626013004: Fix invalid URIs generated using Uri constructor with clever paths. (Closed)
Patch Set: Fix typo, name boolean parameter (address comments). Created 3 years, 11 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
« no previous file with comments | « sdk/lib/core/uri.dart ('k') | no next file » | 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 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 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 void testRegression28359() { 758 void testRegression28359() {
759 var uri = new Uri(path: "//"); 759 var uri = new Uri(path: "//");
760 // This is an invalid path for a URI reference with no authority 760 // This is an invalid path for a URI reference with no authority
761 // since it looks like an authority. 761 // since it looks like an authority.
762 // Normalized to have an authority. 762 // Normalized to have an authority.
763 Expect.equals("////", "$uri"); 763 Expect.equals("////", "$uri");
764 Expect.equals("//", uri.path); 764 Expect.equals("//", uri.path);
765 Expect.isTrue(uri.hasAuthority, "$uri has authority"); 765 Expect.isTrue(uri.hasAuthority, "$uri has authority");
766 766
767 uri = new Uri(path: "file:///wat"); 767 uri = new Uri(path: "file:///wat");
768 // This is an invalid pat for a URI reference with no authority or scheme 768 // This is an invalid path for a URI reference with no authority or scheme
769 // since the path looks like it starts with a scheme. 769 // since the path looks like it starts with a scheme.
770 // Normalized by escaping the ":". 770 // Normalized by escaping the ":".
771 Expect.equals("file%3A///wat", uri.path); 771 Expect.equals("file%3A///wat", uri.path);
772 Expect.equals("file%3A///wat", "$uri"); 772 Expect.equals("file%3A///wat", "$uri");
773 Expect.isFalse(uri.hasAuthority); 773 Expect.isFalse(uri.hasAuthority);
774 Expect.isFalse(uri.hasScheme); 774 Expect.isFalse(uri.hasScheme);
775 } 775 }
776 776
777 main() { 777 main() {
778 testUri("http:", true); 778 testUri("http:", true);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 Uri.parse("https://example.com/a/b/c").origin); 828 Uri.parse("https://example.com/a/b/c").origin);
829 Expect.stringEquals( 829 Expect.stringEquals(
830 "http://example.com:1234", 830 "http://example.com:1234",
831 Uri.parse("http://example.com:1234/a/b/c").origin); 831 Uri.parse("http://example.com:1234/a/b/c").origin);
832 Expect.stringEquals( 832 Expect.stringEquals(
833 "https://example.com:1234", 833 "https://example.com:1234",
834 Uri.parse("https://example.com:1234/a/b/c").origin); 834 Uri.parse("https://example.com:1234/a/b/c").origin);
835 Expect.throws( 835 Expect.throws(
836 () => Uri.parse("http:").origin, 836 () => Uri.parse("http:").origin,
837 (e) { return e is StateError; }, 837 (e) { return e is StateError; },
838 "origin for uri with empty host should fail"); 838 "origin for URI with empty host should fail");
839 Expect.throws( 839 Expect.throws(
840 () => new Uri( 840 () => new Uri(
841 scheme: "http", 841 scheme: "http",
842 userInfo: null, 842 userInfo: null,
843 host: "", 843 host: "",
844 port: 80, 844 port: 80,
845 path: "/a/b/c", 845 path: "/a/b/c",
846 query: "query", 846 query: "query",
847 fragment: "fragment").origin, 847 fragment: "fragment").origin,
848 (e) { return e is StateError; }, 848 (e) { return e is StateError; },
849 "origin for uri with empty host should fail"); 849 "origin for URI with empty host should fail");
850 Expect.throws( 850 Expect.throws(
851 () => new Uri( 851 () => new Uri(
852 scheme: null, 852 scheme: null,
853 userInfo: null, 853 userInfo: null,
854 host: "", 854 host: "",
855 port: 80, 855 port: 80,
856 path: "/a/b/c", 856 path: "/a/b/c",
857 query: "query", 857 query: "query",
858 fragment: "fragment").origin, 858 fragment: "fragment").origin,
859 (e) { return e is StateError; }, 859 (e) { return e is StateError; },
860 "origin for uri with empty scheme should fail"); 860 "origin for URI with empty scheme should fail");
861 Expect.throws( 861 Expect.throws(
862 () => new Uri( 862 () => new Uri(
863 scheme: "http", 863 scheme: "http",
864 userInfo: null, 864 userInfo: null,
865 host: null, 865 host: null,
866 port: 80, 866 port: 80,
867 path: "/a/b/c", 867 path: "/a/b/c",
868 query: "query", 868 query: "query",
869 fragment: "fragment").origin, 869 fragment: "fragment").origin,
870 (e) { return e is StateError; }, 870 (e) { return e is StateError; },
871 "origin for uri with empty host should fail"); 871 "origin for URI with empty host should fail");
872 Expect.throws( 872 Expect.throws(
873 () => Uri.parse("http://:80").origin, 873 () => Uri.parse("http://:80").origin,
874 (e) { return e is StateError; }, 874 (e) { return e is StateError; },
875 "origin for uri with empty host should fail"); 875 "origin for URI with empty host should fail");
876 Expect.throws( 876 Expect.throws(
877 () => Uri.parse("file://localhost/test.txt").origin, 877 () => Uri.parse("file://localhost/test.txt").origin,
878 (e) { return e is StateError; }, 878 (e) { return e is StateError; },
879 "origin for non-http/https uri should fail"); 879 "origin for non-http/https uri should fail");
880 880
881 // URI encode tests 881 // URI encode tests
882 // Create a string with code point 0x10000 encoded as a surrogate pair. 882 // Create a string with code point 0x10000 encoded as a surrogate pair.
883 var s = UTF8.decode([0xf0, 0x90, 0x80, 0x80]); 883 var s = UTF8.decode([0xf0, 0x90, 0x80, 0x80]);
884 884
885 Expect.stringEquals("\u{10000}", s); 885 Expect.stringEquals("\u{10000}", s);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 String dump(Uri uri) { 946 String dump(Uri uri) {
947 return "URI: $uri\n" 947 return "URI: $uri\n"
948 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" 948 " Scheme: ${uri.scheme} #${uri.scheme.length}\n"
949 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" 949 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n"
950 " Host: ${uri.host} #${uri.host.length}\n" 950 " Host: ${uri.host} #${uri.host.length}\n"
951 " Port: ${uri.port}\n" 951 " Port: ${uri.port}\n"
952 " Path: ${uri.path} #${uri.path.length}\n" 952 " Path: ${uri.path} #${uri.path.length}\n"
953 " Query: ${uri.query} #${uri.query.length}\n" 953 " Query: ${uri.query} #${uri.query.length}\n"
954 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; 954 " Fragment: ${uri.fragment} #${uri.fragment.length}\n";
955 } 955 }
OLDNEW
« no previous file with comments | « sdk/lib/core/uri.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698