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

Side by Side Diff: lib/domain.js

Issue 29998564: Issue 7260 - Internalize third-party request check in matcher (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Feb. 5, 2019, 4:04 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/matcher.js » ('j') | lib/matcher.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return hostname; 107 return hostname;
108 108
109 return slices[cutoff]; 109 return slices[cutoff];
110 } 110 }
111 111
112 exports.getDomain = getDomain; 112 exports.getDomain = getDomain;
113 113
114 /** 114 /**
115 * Checks whether a request's origin is different from its document's origin. 115 * Checks whether a request's origin is different from its document's origin.
116 * 116 *
117 * @param {URL} url The request URL. 117 * @param {URL|string} url The request URL.
Sebastian Noack 2019/02/05 04:32:53 Do we even still need to support the case where an
Manish Jethani 2019/02/05 05:07:28 Actually the default is a URL object now, which is
Sebastian Noack 2019/02/05 05:21:16 So why did you add support for passing in strings
Manish Jethani 2019/02/05 05:42:23 It's there for backwards compatibility with (1) li
Sebastian Noack 2019/02/05 05:54:45 I don't get it, you can just make the unit tsts cr
118 * @param {string} documentHostname The IDNA-encoded hostname of the document. 118 * @param {string} documentHostname The IDNA-encoded hostname of the document.
119 * 119 *
120 * @returns {boolean} 120 * @returns {boolean}
121 */ 121 */
122 function isThirdParty(url, documentHostname) 122 function isThirdParty(url, documentHostname)
123 { 123 {
124 let requestHostname = url.hostname; 124 let requestHostname = typeof url == "string" ? new URL(url).hostname :
125 url.hostname;
125 126
126 if (requestHostname[requestHostname.length - 1] == ".") 127 if (requestHostname[requestHostname.length - 1] == ".")
127 requestHostname = requestHostname.replace(/\.+$/, ""); 128 requestHostname = requestHostname.replace(/\.+$/, "");
128 129
129 if (documentHostname[documentHostname.length - 1] == ".") 130 if (documentHostname[documentHostname.length - 1] == ".")
130 documentHostname = documentHostname.replace(/\.+$/, ""); 131 documentHostname = documentHostname.replace(/\.+$/, "");
131 132
132 if (requestHostname == documentHostname) 133 if (requestHostname == documentHostname)
133 return false; 134 return false;
134 135
135 if (!isDomain(requestHostname) || !isDomain(documentHostname)) 136 if (!isDomain(requestHostname) || !isDomain(documentHostname))
136 return true; 137 return true;
137 138
138 return getDomain(requestHostname) != getDomain(documentHostname); 139 return getDomain(requestHostname) != getDomain(documentHostname);
139 } 140 }
140 141
141 exports.isThirdParty = isThirdParty; 142 exports.isThirdParty = isThirdParty;
OLDNEW
« no previous file with comments | « no previous file | lib/matcher.js » ('j') | lib/matcher.js » ('J')

Powered by Google App Engine
This is Rietveld