Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/url.js

Issue 30013574: Issue 7296 - Implement lightweight URL parsing (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Make protocol field required Created Feb. 23, 2019, 7:30 a.m.
Right Patch Set: Remove non-normalized URLs from tests Created Feb. 23, 2019, 8:26 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/url.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 callback(); 44 callback();
45 }; 45 };
46 46
47 function hostnameToURL(hostname) 47 function hostnameToURL(hostname)
48 { 48 {
49 return new URL("http://" + hostname); 49 return new URL("http://" + hostname);
50 } 50 }
51 51
52 function testURLParsing(test, url) 52 function testURLParsing(test, url)
53 { 53 {
54 // The function expects a normalized URL. 54 // Note: The function expects a normalized URL.
55 url = new URL(url).href; 55 // e.g. "http:example.com:80?foo" should already be normalized to
56 56 // "http://example.com/?foo". If not, the tests will fail.
57 let urlInfo = parseURL(url); 57 let urlInfo = parseURL(url);
58 58
59 // We need to ensure only that our implementation matches that of the URL 59 // We need to ensure only that our implementation matches that of the URL
60 // object. 60 // object.
61 let urlObject = new URL(url); 61 let urlObject = new URL(url);
62 62
63 test.equal(urlInfo.href, urlObject.href); 63 test.equal(urlInfo.href, urlObject.href);
64 test.equal(urlInfo.protocol, urlObject.protocol); 64 test.equal(urlInfo.protocol, urlObject.protocol);
65 test.equal(urlInfo.hostname, urlObject.hostname); 65 test.equal(urlInfo.hostname, urlObject.hostname);
66 66
(...skipping 13 matching lines...) Expand all
80 // will fail if we don't normalize the document host as well. 80 // will fail if we don't normalize the document host as well.
81 hostnameToURL(documentHostname).hostname 81 hostnameToURL(documentHostname).hostname
82 ), 82 ),
83 expected, 83 expected,
84 message 84 message
85 ); 85 );
86 } 86 }
87 87
88 exports.testParseURL = function(test) 88 exports.testParseURL = function(test)
89 { 89 {
90 testURLParsing(test, "https://example.com");
91 testURLParsing(test, "https://example.com/"); 90 testURLParsing(test, "https://example.com/");
92 testURLParsing(test, "https://example.com/foo"); 91 testURLParsing(test, "https://example.com/foo");
93 testURLParsing(test, "https://example.com/foo/bar"); 92 testURLParsing(test, "https://example.com/foo/bar");
94 testURLParsing( 93 testURLParsing(
95 test, 94 test,
96 "https://example.com/foo/bar?https://random/foo/bar" 95 "https://example.com/foo/bar?https://random/foo/bar"
97 ); 96 );
98 97
99 testURLParsing(test, "https://example.com:8080");
100 testURLParsing(test, "https://example.com:8080/"); 98 testURLParsing(test, "https://example.com:8080/");
101 testURLParsing(test, "https://example.com:8080/foo"); 99 testURLParsing(test, "https://example.com:8080/foo");
102 testURLParsing(test, "https://example.com:8080/foo/bar"); 100 testURLParsing(test, "https://example.com:8080/foo/bar");
103 testURLParsing( 101 testURLParsing(
104 test, 102 test,
105 "https://example.com:8080/foo/bar?https://random/foo/bar" 103 "https://example.com:8080/foo/bar?https://random/foo/bar"
106 ); 104 );
107 105
108 testURLParsing(test, "http://localhost");
109 testURLParsing(test, "http://localhost/"); 106 testURLParsing(test, "http://localhost/");
110 testURLParsing(test, "http://localhost/foo"); 107 testURLParsing(test, "http://localhost/foo");
111 testURLParsing(test, "http://localhost/foo/bar"); 108 testURLParsing(test, "http://localhost/foo/bar");
112 testURLParsing( 109 testURLParsing(
113 test, 110 test,
114 "http://localhost/foo/bar?https://random/foo/bar" 111 "http://localhost/foo/bar?https://random/foo/bar"
115 ); 112 );
116 113
117 testURLParsing(test, "https://user@example.com");
118 testURLParsing(test, "https://user@example.com/"); 114 testURLParsing(test, "https://user@example.com/");
119 testURLParsing(test, "https://user@example.com/foo"); 115 testURLParsing(test, "https://user@example.com/foo");
120 testURLParsing(test, "https://user@example.com/foo/bar"); 116 testURLParsing(test, "https://user@example.com/foo/bar");
121 testURLParsing( 117 testURLParsing(
122 test, 118 test,
123 "https://user@example.com/foo/bar?https://random/foo/bar" 119 "https://user@example.com/foo/bar?https://random/foo/bar"
124 ); 120 );
125 121
126 testURLParsing(test, "https://user@example.com:8080");
127 testURLParsing(test, "https://user@example.com:8080/"); 122 testURLParsing(test, "https://user@example.com:8080/");
128 testURLParsing(test, "https://user@example.com:8080/foo"); 123 testURLParsing(test, "https://user@example.com:8080/foo");
129 testURLParsing(test, "https://user@example.com:8080/foo/bar"); 124 testURLParsing(test, "https://user@example.com:8080/foo/bar");
130 testURLParsing( 125 testURLParsing(
131 test, 126 test,
132 "https://user@example.com:8080/foo/bar?https://random/foo/bar" 127 "https://user@example.com:8080/foo/bar?https://random/foo/bar"
133 ); 128 );
134 129
135 testURLParsing(test, "https://user:pass@example.com");
136 testURLParsing(test, "https://user:pass@example.com/"); 130 testURLParsing(test, "https://user:pass@example.com/");
137 testURLParsing(test, "https://user:pass@example.com/foo"); 131 testURLParsing(test, "https://user:pass@example.com/foo");
138 testURLParsing(test, "https://user:pass@example.com/foo/bar"); 132 testURLParsing(test, "https://user:pass@example.com/foo/bar");
139 testURLParsing( 133 testURLParsing(
140 test, 134 test,
141 "https://user:pass@example.com/foo/bar?https://random/foo/bar" 135 "https://user:pass@example.com/foo/bar?https://random/foo/bar"
142 ); 136 );
143 137
144 testURLParsing(test, "https://user:pass@example.com:8080");
145 testURLParsing(test, "https://user:pass@example.com:8080/"); 138 testURLParsing(test, "https://user:pass@example.com:8080/");
146 testURLParsing(test, "https://user:pass@example.com:8080/foo"); 139 testURLParsing(test, "https://user:pass@example.com:8080/foo");
147 testURLParsing(test, "https://user:pass@example.com:8080/foo/bar"); 140 testURLParsing(test, "https://user:pass@example.com:8080/foo/bar");
148 testURLParsing( 141 testURLParsing(
149 test, 142 test,
150 "https://user:pass@example.com:8080/foo/bar?https://random/foo/bar" 143 "https://user:pass@example.com:8080/foo/bar?https://random/foo/bar"
151 ); 144 );
152 145
153 testURLParsing(test, "https://us%40er:pa%40ss@example.com");
154 testURLParsing(test, "https://us%40er:pa%40ss@example.com/"); 146 testURLParsing(test, "https://us%40er:pa%40ss@example.com/");
155 testURLParsing(test, "https://us%40er:pa%40ss@example.com/foo"); 147 testURLParsing(test, "https://us%40er:pa%40ss@example.com/foo");
156 testURLParsing(test, "https://us%40er:pa%40ss@example.com/foo/bar"); 148 testURLParsing(test, "https://us%40er:pa%40ss@example.com/foo/bar");
157 testURLParsing( 149 testURLParsing(
158 test, 150 test,
159 "https://us%40er:pa%40ss@example.com/foo/bar?https://random/foo/bar" 151 "https://us%40er:pa%40ss@example.com/foo/bar?https://random/foo/bar"
160 ); 152 );
161 153
162 testURLParsing(test, "https://us%40er:pa%40ss@example.com:8080");
163 testURLParsing(test, "https://us%40er:pa%40ss@example.com:8080/"); 154 testURLParsing(test, "https://us%40er:pa%40ss@example.com:8080/");
164 testURLParsing(test, "https://us%40er:pa%40ss@example.com:8080/foo"); 155 testURLParsing(test, "https://us%40er:pa%40ss@example.com:8080/foo");
165 testURLParsing(test, "https://us%40er:pa%40ss@example.com:8080/foo/bar"); 156 testURLParsing(test, "https://us%40er:pa%40ss@example.com:8080/foo/bar");
166 testURLParsing( 157 testURLParsing(
167 test, 158 test,
168 "https://us%40er:pa%40ss@example.com:8080/foo/bar?https://random/foo/bar" 159 "https://us%40er:pa%40ss@example.com:8080/foo/bar?https://random/foo/bar"
169 ); 160 );
170 161
171 testURLParsing(test, "http://192.168.1.1");
172 testURLParsing(test, "http://192.168.1.1/"); 162 testURLParsing(test, "http://192.168.1.1/");
173 testURLParsing(test, "http://192.168.1.1/foo"); 163 testURLParsing(test, "http://192.168.1.1/foo");
174 testURLParsing(test, "http://192.168.1.1/foo/bar"); 164 testURLParsing(test, "http://192.168.1.1/foo/bar");
175 testURLParsing( 165 testURLParsing(
176 test, 166 test,
177 "http://192.168.1.1/foo/bar?https://random/foo/bar" 167 "http://192.168.1.1/foo/bar?https://random/foo/bar"
178 ); 168 );
179 testURLParsing( 169 testURLParsing(
180 test, 170 test,
181 "http://192.168.1.1:8080/foo/bar?https://random/foo/bar" 171 "http://192.168.1.1:8080/foo/bar?https://random/foo/bar"
182 ); 172 );
183 testURLParsing( 173 testURLParsing(
184 test, 174 test,
185 "http://user@192.168.1.1:8080/foo/bar?https://random/foo/bar" 175 "http://user@192.168.1.1:8080/foo/bar?https://random/foo/bar"
186 ); 176 );
187 testURLParsing( 177 testURLParsing(
188 test, 178 test,
189 "http://user:pass@192.168.1.1:8080/foo/bar?https://random/foo/bar" 179 "http://user:pass@192.168.1.1:8080/foo/bar?https://random/foo/bar"
190 ); 180 );
191 181
192 testURLParsing(test, "http://[2001:0db8:0000:0042:0000:8a2e:0370:7334]"); 182 testURLParsing(test, "http://[2001:db8:0:42:0:8a2e:370:7334]/");
193 testURLParsing(test, "http://[2001:0db8:0000:0042:0000:8a2e:0370:7334]/"); 183 testURLParsing(test, "http://[2001:db8:0:42:0:8a2e:370:7334]/foo");
194 testURLParsing(test, "http://[2001:0db8:0000:0042:0000:8a2e:0370:7334]/foo"); 184 testURLParsing(
195 testURLParsing( 185 test,
196 test, 186 "http://[2001:db8:0:42:0:8a2e:370:7334]/foo/bar"
197 "http://[2001:0db8:0000:0042:0000:8a2e:0370:7334]/foo/bar" 187 );
198 ); 188 testURLParsing(
199 testURLParsing( 189 test,
200 test, 190 "http://[2001:db8:0:42:0:8a2e:370:7334]/foo/bar?https://random/foo/bar"
201 "http://[2001:0db8:0000:0042:0000:8a2e:0370:7334]/foo/bar?https://random/foo /bar" 191 );
202 ); 192 testURLParsing(
203 testURLParsing( 193 test,
204 test, 194 "http://[2001:db8:0:42:0:8a2e:370:7334]:8080/foo/bar?https://random/foo/bar"
205 "http://[2001:0db8:0000:0042:0000:8a2e:0370:7334]:8080/foo/bar?https://rando m/foo/bar" 195 );
206 ); 196 testURLParsing(
207 testURLParsing( 197 test,
208 test, 198 "http://user@[2001:db8:0:42:0:8a2e:370:7334]:8080/foo/bar?https://random/foo /bar"
209 "http://user@[2001:0db8:0000:0042:0000:8a2e:0370:7334]:8080/foo/bar?https:// random/foo/bar" 199 );
210 ); 200 testURLParsing(
211 testURLParsing( 201 test,
212 test, 202 "http://user:pass@[2001:db8:0:42:0:8a2e:370:7334]:8080/foo/bar?https://rando m/foo/bar"
213 "http://user:pass@[2001:0db8:0000:0042:0000:8a2e:0370:7334]:8080/foo/bar?htt ps://random/foo/bar" 203 );
214 ); 204
215
216 testURLParsing(test, "ftp://user:pass@example.com:8021");
217 testURLParsing(test, "ftp://user:pass@example.com:8021/"); 205 testURLParsing(test, "ftp://user:pass@example.com:8021/");
218 testURLParsing(test, "ftp://user:pass@example.com:8021/foo"); 206 testURLParsing(test, "ftp://user:pass@example.com:8021/foo");
219 testURLParsing(test, "ftp://user:pass@example.com:8021/foo/bar"); 207 testURLParsing(test, "ftp://user:pass@example.com:8021/foo/bar");
220 208
221 testURLParsing(test, "about:blank"); 209 testURLParsing(test, "about:blank");
222 testURLParsing(test, "chrome://extensions"); 210 testURLParsing(test, "chrome://extensions");
223 testURLParsing( 211 testURLParsing(
224 test, 212 test,
225 "chrome-extension://bhignfpcigccnlfapldlodmhlidjaion/options.html" 213 "chrome-extension://bhignfpcigccnlfapldlodmhlidjaion/options.html"
226 ); 214 );
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 ); 268 );
281 269
282 testURLParsing(test, "javascript:window.alert('hello, world');"); 270 testURLParsing(test, "javascript:window.alert('hello, world');");
283 testURLParsing(test, "javascript:#"); 271 testURLParsing(test, "javascript:#");
284 272
285 testURLParsing( 273 testURLParsing(
286 test, 274 test,
287 "blob:https://example.com/7ce70a1e-9681-4148-87a8-43cb9171b994" 275 "blob:https://example.com/7ce70a1e-9681-4148-87a8-43cb9171b994"
288 ); 276 );
289 277
290 testURLParsing(test, "http://[2001:db8::1]"); 278 testURLParsing(test, "http://[2001:db8::1]/");
291 testURLParsing(test, "http://[2001:db8::1]:8080"); 279 testURLParsing(test, "http://[2001:db8::1]:8080/");
292 testURLParsing(test, "http://[::]:8080"); 280 testURLParsing(test, "http://[::]:8080/");
293 281
294 testURLParsing(test, "not-a-standard-scheme:this is arbitrary content"); 282 testURLParsing(test, "not-a-standard-scheme:this is arbitrary content");
295 testURLParsing(test, "view-source:http://example.com/path"); 283 testURLParsing(test, "view-source:http://example.com/path");
296 284
297 testURLParsing( 285 testURLParsing(
298 test, 286 test,
299 "data:text/html,Question?%3Cdiv%20style=%22color:%20#bad%22%3Eidea%3C/div%3E " 287 "data:text/html,Question?%3Cdiv%20style=%22color:%20#bad%22%3Eidea%3C/div%3E "
300 ); 288 );
301 289
302 test.done(); 290 test.done();
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 "us-east-1.amazonaws.com" 514 "us-east-1.amazonaws.com"
527 ); 515 );
528 test.equal(getBaseDomain("example.amazonaws.com"), "amazonaws.com"); 516 test.equal(getBaseDomain("example.amazonaws.com"), "amazonaws.com");
529 test.equal(getBaseDomain("amazonaws.com"), "amazonaws.com"); 517 test.equal(getBaseDomain("amazonaws.com"), "amazonaws.com");
530 518
531 // Edge case. 519 // Edge case.
532 test.equal(getBaseDomain(""), ""); 520 test.equal(getBaseDomain(""), "");
533 521
534 test.done(); 522 test.done();
535 }; 523 };
LEFTRIGHT
« lib/url.js ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld