A free and open-source block-based email template builder.
TypeScript amazonsesdeveloper-toolsemailemail-editoremail-marketingemail-templateemail-template-builderemailapiemailjshtml-email-editorno-codenocode-email-editoropen-source-email-buildersendgridtransactional-emailswysiwyg-email-editorwysiwyg-html-editor
Fixing error when sanitizing empty url attributes (#179)
cohitre385cd610d1ed
diff --git a/packages/block-text/src/EmailMarkdown.tsx b/packages/block-text/src/EmailMarkdown.tsxindex ef7cafb..2877efd 100644--- a/packages/block-text/src/EmailMarkdown.tsx+++ b/packages/block-text/src/EmailMarkdown.tsx@@ -50,12 +50,13 @@ const GENERIC_ALLOWED_ATTRIBUTES = ['style', 'title'];function sanitizer(html: string): string {return insane(html, {allowedTags: ALLOWED_TAGS,+ allowedSchemes: ['http', 'https', 'mailto'],allowedAttributes: {...ALLOWED_TAGS.reduce<Record<string, string[]>>((res, tag) => {res[tag] = [...GENERIC_ALLOWED_ATTRIBUTES];return res;}, {}),- img: ['src', 'srcset', 'alt', 'width', 'height', ...GENERIC_ALLOWED_ATTRIBUTES],+ img: ['src', 'alt', 'width', 'height', ...GENERIC_ALLOWED_ATTRIBUTES],table: ['width', ...GENERIC_ALLOWED_ATTRIBUTES],td: ['align', 'width', ...GENERIC_ALLOWED_ATTRIBUTES],th: ['align', 'width', ...GENERIC_ALLOWED_ATTRIBUTES],@@ -63,6 +64,15 @@ function sanitizer(html: string): string {ol: ['start', ...GENERIC_ALLOWED_ATTRIBUTES],ul: ['start', ...GENERIC_ALLOWED_ATTRIBUTES],},+ filter: (token) => {+ if (token.tag === 'a' && 'href' in token.attrs && token.attrs.href === undefined) {+ token.attrs.href = '';+ }+ if (token.tag === 'img' && 'src' in token.attrs && token.attrs.src === undefined) {+ token.attrs.src = '';+ }+ return true;+ },});}diff --git a/packages/block-text/src/__snapshots__/index.spec.tsx.snap b/packages/block-text/src/__snapshots__/index.spec.tsx.snapindex dfc9161..0e9d091 100644--- a/packages/block-text/src/__snapshots__/index.spec.tsx.snap+++ b/packages/block-text/src/__snapshots__/index.spec.tsx.snap@@ -157,6 +157,60 @@ exports[`block-text sanitizes HTML 1`] = `</p>+ <div>+++ <img+ src=""+ />+++ <a>+ link 1+ </a>+++ <a+ href=""+ >+ link 2+ </a>+++ <a+ href=""+ >+ link 3+ </a>+++ <a+ title=""+ >+ link 4+ </a>+++ <a+ title=""+ >+ link 5+ </a>+++ <a>+ link 6+ </a>+++ <a>+ link 7+ </a>+++ </div>++</div></DocumentFragment>`;diff --git a/packages/block-text/src/index.spec.tsx b/packages/block-text/src/index.spec.tsxindex 43362fa..ea75eec 100644--- a/packages/block-text/src/index.spec.tsx+++ b/packages/block-text/src/index.spec.tsx@@ -34,6 +34,17 @@ describe('block-text', () => {)))++<div>+<img src />+<a>link 1</a>+<a href>link 2</a>+<a href="">link 3</a>+<a title>link 4</a>+<a title="">link 5</a>+<a href="ftp://domain.name">link 6</a>+<a href="javascript:alert('hello world')">link 7</a>+</div>`,}}/>diff --git a/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/TextSidebarPanel.tsx b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/TextSidebarPanel.tsxindex 3ef17fb..26c3009 100644--- a/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/TextSidebarPanel.tsx+++ b/packages/editor-sample/src/App/InspectorDrawer/ConfigurationPanel/input-panels/TextSidebarPanel.tsx@@ -33,7 +33,7 @@ export default function TextSidebarPanel({ data, setData }: TextSidebarPanelProponChange={(text) => updateData({ ...data, props: { ...data.props, text } })}/><BooleanInput- label="Markdown"+ label="Markdown (GitHub flavored)"defaultValue={data.props?.markdown ?? false}onChange={(markdown) => updateData({ ...data, props: { ...data.props, markdown } })}/>