Skip to content

Commit

Permalink
Make sanitizer fail entirely on any errors (#1725)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube authored Jan 1, 2025
1 parent 2157d69 commit ec30c97
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions ext/js/core/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {log} from './log.js';


/**
* Converts any string into a form that can be passed into the RegExp constructor.
Expand Down Expand Up @@ -271,15 +269,7 @@ export function promiseTimeout(delay) {
* @returns {string}
*/
export function sanitizeCSS(css) {
let sanitizer;
// As of 2023/03/xx, all latest browser versions support this but some forks may lag behind
try {
sanitizer = new CSSStyleSheet();
} catch (e) {
log.log('Failed to sanitize dictionary styles');
log.warn(e);
return css;
}
const sanitizer = new CSSStyleSheet();
sanitizer.replaceSync(css);
return [...sanitizer.cssRules].map((rule) => rule.cssText || '').join('\n');
}

0 comments on commit ec30c97

Please sign in to comment.