| 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('../../lib/utf/utf.dart'); | 7 #import('../../lib/utf/utf.dart'); |
| 8 #import('../../lib/uri/uri.dart'); | 8 #import('../../lib/uri/uri.dart'); |
| 9 | 9 |
| 10 testUri(String uri, bool isAbsolute) { | 10 testUri(String uri, bool isAbsolute) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 Expect.stringEquals("a/b/e/", removeDotSegments("./a/b/./c/d/../../e/.")); | 111 Expect.stringEquals("a/b/e/", removeDotSegments("./a/b/./c/d/../../e/.")); |
| 112 Expect.stringEquals("a/b/e/", removeDotSegments("./a/b/./c/d/../../e/./.")); | 112 Expect.stringEquals("a/b/e/", removeDotSegments("./a/b/./c/d/../../e/./.")); |
| 113 Expect.stringEquals("a/b/e/", removeDotSegments("./a/b/./c/d/../../e/././.")); | 113 Expect.stringEquals("a/b/e/", removeDotSegments("./a/b/./c/d/../../e/././.")); |
| 114 | 114 |
| 115 final urisSample = "http://a/b/c/d;p?q"; | 115 final urisSample = "http://a/b/c/d;p?q"; |
| 116 Uri baseFromString = new Uri.fromString(urisSample); | 116 Uri baseFromString = new Uri.fromString(urisSample); |
| 117 testUriPerRFCs(baseFromString); | 117 testUriPerRFCs(baseFromString); |
| 118 Uri base = new Uri(urisSample); | 118 Uri base = new Uri(urisSample); |
| 119 testUriPerRFCs(base); | 119 testUriPerRFCs(base); |
| 120 | 120 |
| 121 Expect.stringEquals( |
| 122 "http://example.com", |
| 123 new Uri.fromString("http://example.com/a/b/c").origin); |
| 124 Expect.stringEquals( |
| 125 "https://example.com", |
| 126 new Uri.fromString("https://example.com/a/b/c").origin); |
| 127 Expect.stringEquals( |
| 128 "http://example.com:1234", |
| 129 new Uri.fromString("http://example.com:1234/a/b/c").origin); |
| 130 Expect.stringEquals( |
| 131 "https://example.com:1234", |
| 132 new Uri.fromString("https://example.com:1234/a/b/c").origin); |
| 133 Expect.throws( |
| 134 () => new Uri.fromString("http:").origin, |
| 135 (e) { return e is IllegalArgumentException; }, |
| 136 "origin for uri with empty domain should fail"); |
| 137 Expect.throws( |
| 138 () => const Uri.fromComponents("http", null, "", 80, "/a/b/c", |
| 139 "query", "fragment").origin, |
| 140 (e) { return e is IllegalArgumentException; }, |
| 141 "origin for uri with empty domain should fail"); |
| 142 Expect.throws( |
| 143 () => const Uri.fromComponents(null, null, "", 80, "/a/b/c", |
| 144 "query", "fragment").origin, |
| 145 (e) { return e is IllegalArgumentException; }, |
| 146 "origin for uri with empty scheme should fail"); |
| 147 Expect.throws( |
| 148 () => const Uri.fromComponents("http", null, null, 80, "/a/b/c", |
| 149 "query", "fragment").origin, |
| 150 (e) { return e is IllegalArgumentException; }, |
| 151 "origin for uri with empty domain should fail"); |
| 152 Expect.throws( |
| 153 () => new Uri.fromString("http://:80").origin, |
| 154 (e) { return e is IllegalArgumentException; }, |
| 155 "origin for uri with empty domain should fail"); |
| 156 Expect.throws( |
| 157 () => new Uri.fromString("file://localhost/test.txt").origin, |
| 158 (e) { return e is IllegalArgumentException; }, |
| 159 "origin for non-http/https uri should fail"); |
| 160 |
| 121 // URI encode tests | 161 // URI encode tests |
| 122 // Note: dart2js won't handle '\ud800\udc00' and frog | 162 // Note: dart2js won't handle '\ud800\udc00' and frog |
| 123 // won't handle '\u{10000}'. So we cons this up synthetically... | 163 // won't handle '\u{10000}'. So we cons this up synthetically... |
| 124 var s = decodeUtf8([0xf0, 0x90, 0x80, 0x80]); | 164 var s = decodeUtf8([0xf0, 0x90, 0x80, 0x80]); |
| 125 | 165 |
| 126 testEncodeDecode("\uFFFE", "%EF%BF%BE"); | 166 testEncodeDecode("\uFFFE", "%EF%BF%BE"); |
| 127 testEncodeDecode("\uFFFF", "%EF%BF%BF"); | 167 testEncodeDecode("\uFFFF", "%EF%BF%BF"); |
| 128 testEncodeDecode("\uFFFE", "%EF%BF%BE"); | 168 testEncodeDecode("\uFFFE", "%EF%BF%BE"); |
| 129 testEncodeDecode("\uFFFF", "%EF%BF%BF"); | 169 testEncodeDecode("\uFFFF", "%EF%BF%BF"); |
| 130 testEncodeDecode("\x7f", "%7F"); | 170 testEncodeDecode("\x7f", "%7F"); |
| 131 testEncodeDecode("\x80", "%C2%80"); | 171 testEncodeDecode("\x80", "%C2%80"); |
| 132 testEncodeDecode("\u0800", "%E0%A0%80"); | 172 testEncodeDecode("\u0800", "%E0%A0%80"); |
| 133 testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=+\$"); | 173 testEncodeDecode(":/@',;?&=+\$", ":/@',;?&=+\$"); |
| 134 testEncodeDecode(s, "%F0%90%80%80"); | 174 testEncodeDecode(s, "%F0%90%80%80"); |
| 135 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); | 175 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
| 136 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); | 176 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
| 137 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); | 177 testEncodeDecodeComponent("\uFFFE", "%EF%BF%BE"); |
| 138 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); | 178 testEncodeDecodeComponent("\uFFFF", "%EF%BF%BF"); |
| 139 testEncodeDecodeComponent("\x7f", "%7F"); | 179 testEncodeDecodeComponent("\x7f", "%7F"); |
| 140 testEncodeDecodeComponent("\x80", "%C2%80"); | 180 testEncodeDecodeComponent("\x80", "%C2%80"); |
| 141 testEncodeDecodeComponent("\u0800", "%E0%A0%80"); | 181 testEncodeDecodeComponent("\u0800", "%E0%A0%80"); |
| 142 testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24"); | 182 testEncodeDecodeComponent(":/@',;?&=+\$", "%3A%2F%40'%2C%3B%3F%26%3D%2B%24"); |
| 143 testEncodeDecodeComponent(s, "%F0%90%80%80"); | 183 testEncodeDecodeComponent(s, "%F0%90%80%80"); |
| 144 } | 184 } |
| OLD | NEW |