Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions emails/testsuite/transformer/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,32 @@ def test_tag_attribute():
assert m3.attachments['1.jpg'].content_disposition == "inline"


def test_data_uri_preserved():
DATA_URI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="

# data URIs in img src should be left untouched
html = '<img src="%s"/>' % DATA_URI
m = emails.loader.from_string(html=html)
assert len(m.attachments.keys()) == 0
assert DATA_URI in m.html

# data URIs in css url() should be left untouched
html = '<div style="background: url(%s);">x</div>' % DATA_URI
m = emails.loader.from_string(html=html)
assert len(m.attachments.keys()) == 0

# data URIs in background attribute should be left untouched
html = '<table background="%s"/>' % DATA_URI
m = emails.loader.from_string(html=html)
assert len(m.attachments.keys()) == 0

# mixed-case scheme should also be preserved
mixed = DATA_URI.replace('data:', 'Data:')
html = '<img src="%s"/>' % mixed
m = emails.loader.from_string(html=html)
assert len(m.attachments.keys()) == 0


ROOT = os.path.dirname(__file__)

def test_local_premailer():
Expand Down
3 changes: 3 additions & 0 deletions emails/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ def _load_attachment_func(self, uri, element=None, callback=None, **kw):
# Return local uri
#

if uri[:5].lower() == 'data:':
return uri

if callback is None:
# Default callback: skip images with data-emails="ignore" attribute
callback = lambda _, hints: hints['attrib'] != 'ignore'
Expand Down
Loading