lettersanitizer
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -20,2 +20,3 @@ export interface SanitizerOptions { | ||
* Allowed schemas, default: ['http', 'https', 'mailto']. | ||
* Does not apply if rewriteExternalResources and/or rewriteExternalLinks are enabled. | ||
*/ | ||
@@ -22,0 +23,0 @@ allowedSchemas?: string[]; |
@@ -29,17 +29,8 @@ "use strict"; | ||
.replace(/url\(["']?(.*?)["']?\)/g, (match, url) => { | ||
let quote = ''; | ||
if (match.startsWith('url("')) { | ||
quote = '"'; | ||
if (rewriteExternalResources) { | ||
return `url("${encodeURI(rewriteExternalResources(decodeURI(url)))}")`; | ||
} | ||
else if (match.startsWith("url('")) { | ||
quote = "'"; | ||
else if (allowedSchemas.includes(url.toLowerCase().split(':')[0])) { | ||
return match; | ||
} | ||
if (allowedSchemas.includes(url.toLowerCase().split(':')[0])) { | ||
if (rewriteExternalResources) { | ||
return 'url(' + quote + rewriteExternalResources(url) + quote + ')'; | ||
} | ||
else { | ||
return match; | ||
} | ||
} | ||
else { | ||
@@ -142,6 +133,3 @@ return ''; | ||
const value = (_g = element.getAttribute(attribute)) !== null && _g !== void 0 ? _g : ''; | ||
if (!allowedSchemas.includes(value.toLowerCase().split(':')[0])) { | ||
element.removeAttribute(attribute); | ||
} | ||
else if (attribute === 'href' && rewriteExternalLinks) { | ||
if (attribute === 'href' && rewriteExternalLinks) { | ||
element.setAttribute(attribute, rewriteExternalLinks(value)); | ||
@@ -152,2 +140,5 @@ } | ||
} | ||
else if (!allowedSchemas.includes(value.toLowerCase().split(':')[0])) { | ||
element.removeAttribute(attribute); | ||
} | ||
} | ||
@@ -154,0 +145,0 @@ } |
{ | ||
"name": "lettersanitizer", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "DOM-based HTML email sanitizer for in-browser email rendering.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
23862
648