Skip to content

Commit

Permalink
Embeds: Fixed crash when no HTML field is sent back from the embed pr…
Browse files Browse the repository at this point in the history
…ovider
  • Loading branch information
kaedroho committed Jun 25, 2014
1 parent af8b6cd commit 6157b16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions wagtail/wagtailembeds/embeds.py
Expand Up @@ -162,6 +162,10 @@ def get_embed(url, max_width=None, finder=None):
except (TypeError, ValueError):
embed_dict['height'] = None

# Make sure html field is valid
if 'html' not in embed_dict or not embed_dict['html']:
embed_dict['html'] = ''

# Create database record
embed, created = Embed.objects.get_or_create(
url=url,
Expand Down
13 changes: 13 additions & 0 deletions wagtail/wagtailembeds/tests.py
Expand Up @@ -81,6 +81,19 @@ def test_invalid_width(self):
# Width must be set to None
self.assertEqual(embed.width, None)

def test_no_html(self) :
def no_html_finder(url, max_width=None):
"""
A finder which returns everything but HTML
"""
embed = self.dummy_finder(url, max_width)
embed['html'] = None
return embed

embed = get_embed('www.test.com/1234', max_width=400, finder=no_html_finder)

self.assertEqual(embed.html, '')


class TestChooser(TestCase):
def setUp(self):
Expand Down

0 comments on commit 6157b16

Please sign in to comment.