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

Delta Between Two Patch Sets: lib/url.js

Issue 30013574: Issue 7296 - Implement lightweight URL parsing (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Add more tests Created Feb. 21, 2019, 2:01 p.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 | « no previous file | test/url.js » ('j') | 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 /** 42 /**
43 * A <code>URLInfo</code> object represents information about a URL. It is 43 * A <code>URLInfo</code> object represents information about a URL. It is
44 * returned by <code>{@link parseURL}</code>. 44 * returned by <code>{@link parseURL}</code>.
45 */ 45 */
46 class URLInfo 46 class URLInfo
47 { 47 {
48 /** 48 /**
49 * Creates a <code>URLInfo</code> object. 49 * Creates a <code>URLInfo</code> object.
50 * 50 *
51 * @param {string} href The entire URL. 51 * @param {string} href The entire URL.
52 * @param {string} [protocol] The protocol scheme of the URL, including the 52 * @param {string} protocol The protocol scheme of the URL, including the
53 * final <code>:</code>. 53 * final <code>:</code>.
54 * @param {string} [hostname] The hostname of the URL. 54 * @param {string} [hostname] The hostname of the URL.
55 * 55 *
56 * @private 56 * @private
57 */ 57 */
58 constructor(href, protocol = "", hostname = "") 58 constructor(href, protocol, hostname = "")
59 { 59 {
60 this._href = href; 60 this._href = href;
61 this._protocol = protocol; 61 this._protocol = protocol;
62 this._hostname = hostname; 62 this._hostname = hostname;
63 } 63 }
64 64
65 /** 65 /**
66 * The entire URL. 66 * The entire URL.
67 * @type {string} 67 * @type {string}
68 */ 68 */
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 * <code>URL</code> object, this function is not robust and will give incorrect 105 * <code>URL</code> object, this function is not robust and will give incorrect
106 * results for invalid URLs. <em>Use this function with valid, normalized, 106 * results for invalid URLs. <em>Use this function with valid, normalized,
107 * properly encoded (IDNA and percent-encoding) URLs only.</em> 107 * properly encoded (IDNA and percent-encoding) URLs only.</em>
108 * 108 *
109 * @param {string} url The URL to parse. 109 * @param {string} url The URL to parse.
110 * @returns {URLInfo} Information about the URL. 110 * @returns {URLInfo} Information about the URL.
111 */ 111 */
112 function parseURL(url) 112 function parseURL(url)
113 { 113 {
114 let match = /^([^:]+:)(?:\/\/(?:[^/]*@)?(\[[^\]]*\]|[^:/]+))?/.exec(url); 114 let match = /^([^:]+:)(?:\/\/(?:[^/]*@)?(\[[^\]]*\]|[^:/]+))?/.exec(url);
115 return match ? new URLInfo(url, match[1], match[2]) : new URLInfo(url); 115 return new URLInfo(url, match[1], match[2]);
hub 2019/02/21 16:24:08 if the parsing fails, then we only have a valid `_
Manish Jethani 2019/02/23 07:32:05 Actually since the function assumes that the URL w
116 } 116 }
117 117
118 exports.parseURL = parseURL; 118 exports.parseURL = parseURL;
119 119
120 /** 120 /**
121 * Normalizes a hostname. 121 * Normalizes a hostname.
122 * @param {string} hostname 122 * @param {string} hostname
123 * @returns {string} 123 * @returns {string}
124 */ 124 */
125 function normalizeHostname(hostname) 125 function normalizeHostname(hostname)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 if (requestHostname == documentHostname) 231 if (requestHostname == documentHostname)
232 return false; 232 return false;
233 233
234 if (!isDomain(requestHostname) || !isDomain(documentHostname)) 234 if (!isDomain(requestHostname) || !isDomain(documentHostname))
235 return true; 235 return true;
236 236
237 return getBaseDomain(requestHostname) != getBaseDomain(documentHostname); 237 return getBaseDomain(requestHostname) != getBaseDomain(documentHostname);
238 } 238 }
239 239
240 exports.isThirdParty = isThirdParty; 240 exports.isThirdParty = isThirdParty;
LEFTRIGHT
« no previous file | test/url.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld