Ensure unique selectors for loaded extension files

This commit is contained in:
Cohee
2025-01-09 22:32:15 +02:00
parent a8b5f8a95f
commit f869b26664
2 changed files with 17 additions and 5 deletions

View File

@ -67,6 +67,16 @@ export function escapeHtml(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
/**
* Make string safe for use as a CSS selector.
* @param {string} str String to sanitize
* @param {string} replacement Replacement for invalid characters
* @returns {string} Sanitized string
*/
export function sanitizeSelector(str, replacement = '_') {
return String(str).replace(/[^a-z0-9_-]/ig, replacement);
}
export function isValidUrl(value) {
try {
new URL(value);