Skip to content

Commit

Permalink
Catch sanitizer fails only when new CSSStyleSheet() is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Dec 29, 2024
1 parent 74978b2 commit 449ee64
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ext/js/core/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* 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.
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
Expand Down Expand Up @@ -268,7 +271,15 @@ export function promiseTimeout(delay) {
* @returns {string}
*/
export function sanitizeCSS(css) {
const sanitizer = new CSSStyleSheet();
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")

Check failure on line 279 in ext/js/core/utilities.js

View workflow job for this annotation

GitHub Actions / JavaScript

Strings must use singlequote

Check failure on line 279 in ext/js/core/utilities.js

View workflow job for this annotation

GitHub Actions / JavaScript

Missing semicolon
log.warn(e);
return css;
}
sanitizer.replaceSync(css);
return Array.from(sanitizer.cssRules).map(rule => rule.cssText || '').join('\n');

Check failure on line 284 in ext/js/core/utilities.js

View workflow job for this annotation

GitHub Actions / JavaScript

Prefer the spread operator over `Array.from(…)`

Check failure on line 284 in ext/js/core/utilities.js

View workflow job for this annotation

GitHub Actions / JavaScript

Expected parentheses around arrow function argument
}

0 comments on commit 449ee64

Please sign in to comment.