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

Side by Side Diff: lib/elemHide.js

Issue 30002580: Noissue - Abstract hostname normalization (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add tests Created Feb. 8, 2019, 7:26 p.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 | « lib/domain.js ('k') | lib/filterClasses.js » ('j') | no next file with comments »
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 /** 20 /**
21 * @fileOverview Element hiding implementation. 21 * @fileOverview Element hiding implementation.
22 */ 22 */
23 23
24 const {ElemHideExceptions} = require("./elemHideExceptions"); 24 const {ElemHideExceptions} = require("./elemHideExceptions");
25 const {filterNotifier} = require("./filterNotifier"); 25 const {filterNotifier} = require("./filterNotifier");
26 const {suffixes} = require("./domain"); 26 const {normalizeHostname, suffixes} = require("./domain");
27 27
28 /** 28 /**
29 * The maximum number of selectors in a CSS rule. This is used by 29 * The maximum number of selectors in a CSS rule. This is used by
30 * <code>{@link createStyleSheet}</code> to split up a long list of selectors 30 * <code>{@link createStyleSheet}</code> to split up a long list of selectors
31 * into multiple rules. 31 * into multiple rules.
32 * @const {number} 32 * @const {number}
33 * @default 33 * @default
34 */ 34 */
35 const selectorGroupSize = 1024; 35 const selectorGroupSize = 1024;
36 36
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 * 391 *
392 * @returns {ElemHideStyleSheet} An object containing the CSS code and the 392 * @returns {ElemHideStyleSheet} An object containing the CSS code and the
393 * list of selectors. 393 * list of selectors.
394 */ 394 */
395 generateStyleSheetForDomain(domain, specificOnly = false, 395 generateStyleSheetForDomain(domain, specificOnly = false,
396 includeSelectors = false) 396 includeSelectors = false)
397 { 397 {
398 let code = null; 398 let code = null;
399 let selectors = null; 399 let selectors = null;
400 400
401 if (domain[domain.length - 1] == ".") 401 domain = normalizeHostname(domain);
402 domain = domain.replace(/\.+$/, "");
403
404 domain = domain.toLowerCase();
405 402
406 if (specificOnly) 403 if (specificOnly)
407 { 404 {
408 selectors = getConditionalSelectors(domain, true); 405 selectors = getConditionalSelectors(domain, true);
409 code = createStyleSheet(selectors); 406 code = createStyleSheet(selectors);
410 } 407 }
411 else 408 else
412 { 409 {
413 let knownSuffix = getKnownSuffix(domain); 410 let knownSuffix = getKnownSuffix(domain);
414 411
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 { 503 {
507 let styleSheet = ""; 504 let styleSheet = "";
508 505
509 for (let selectorGroup of splitSelectors(selectors)) 506 for (let selectorGroup of splitSelectors(selectors))
510 styleSheet += createRule(selectorGroup); 507 styleSheet += createRule(selectorGroup);
511 508
512 return styleSheet; 509 return styleSheet;
513 } 510 }
514 511
515 exports.createStyleSheet = createStyleSheet; 512 exports.createStyleSheet = createStyleSheet;
OLDNEW
« no previous file with comments | « lib/domain.js ('k') | lib/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld