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

Delta Between Two Patch Sets: lib/elemHide.js

Issue 30002601: Issue 7284 - Move CSS escaping to createStyleSheet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Feb. 9, 2019, 12:41 a.m.
Right Patch Set: more nits Created Feb. 18, 2019, 1:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « lib/content/elemHideEmulation.js ('k') | lib/filterClasses.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
(no file at all)
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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 // calculate the sizes of the selectors and divide them up accordingly, but 470 // calculate the sizes of the selectors and divide them up accordingly, but
471 // this approach is more efficient and has worked well in practice. In theory 471 // this approach is more efficient and has worked well in practice. In theory
472 // this could still lead to some selectors not working on Chromium, but it is 472 // this could still lead to some selectors not working on Chromium, but it is
473 // highly unlikely. 473 // highly unlikely.
474 // See issue #6298 and https://crbug.com/804179 474 // See issue #6298 and https://crbug.com/804179
475 for (let i = 0; i < selectors.length; i += selectorGroupSize) 475 for (let i = 0; i < selectors.length; i += selectorGroupSize)
476 yield selectors.slice(i, i + selectorGroupSize); 476 yield selectors.slice(i, i + selectorGroupSize);
477 } 477 }
478 478
479 /** 479 /**
480 * Escapes curly braces to prevent CSS rule injection.
481 *
482 * @param {string} selector
483 * @returns {string}
484 */
485 function escapeSelector(selector)
486 {
487 return selector.replace("{", "\\7B ").replace("}", "\\7D ");
488 }
489
490 /**
480 * Creates an element hiding CSS rule for a given list of selectors. 491 * Creates an element hiding CSS rule for a given list of selectors.
481 * 492 *
482 * @param {Array.<string>} selectors 493 * @param {Array.<string>} selectors
483 * @returns {string} 494 * @returns {string}
484 */ 495 */
485 function createRule(selectors) 496 function createRule(selectors)
486 { 497 {
487 let rule = ""; 498 let rule = "";
488 499
489 for (let i = 0; i < selectors.length - 1; i++) 500 for (let i = 0; i < selectors.length - 1; i++)
490 rule += selectors[i] + ", "; 501 rule += escapeSelector(selectors[i]) + ", ";
491 502
492 rule += selectors[selectors.length - 1] + " {display: none !important;}\n"; 503 rule += escapeSelector(selectors[selectors.length - 1]) +
504 " {display: none !important;}\n";
493 505
494 return rule; 506 return rule;
495 } 507 }
496 508
497 /** 509 /**
498 * Creates an element hiding CSS style sheet from a given list of selectors. 510 * Creates an element hiding CSS style sheet from a given list of selectors.
499 * @param {Array.<string>} selectors 511 * @param {Array.<string>} selectors
500 * @returns {string} 512 * @returns {string}
501 */ 513 */
502 function createStyleSheet(selectors) 514 function createStyleSheet(selectors)
503 { 515 {
504 let styleSheet = ""; 516 let styleSheet = "";
505 517
506 for (let selectorGroup of splitSelectors(selectors)) 518 for (let selectorGroup of splitSelectors(selectors))
507 styleSheet += createRule(selectorGroup); 519 styleSheet += createRule(selectorGroup);
508 520
509 return styleSheet; 521 return styleSheet;
510 } 522 }
511 523
512 exports.createStyleSheet = createStyleSheet; 524 exports.createStyleSheet = createStyleSheet;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld