kopia lustrzana https://github.com/wagtail/wagtail
Fixed crash when an invalid width is send by oembed provider
rodzic
280d960829
commit
27debc3289
|
|
@ -152,6 +152,17 @@ def get_embed(url, max_width=None, finder=None):
|
|||
finder = get_default_finder()
|
||||
embed_dict = finder(url, max_width)
|
||||
|
||||
# Make sure width and height are valid integers before inserting into database
|
||||
try:
|
||||
embed_dict['width'] = int(embed_dict['width'])
|
||||
except ValueError:
|
||||
embed_dict['width'] = None
|
||||
|
||||
try:
|
||||
embed_dict['height'] = int(embed_dict['height'])
|
||||
except ValueError:
|
||||
embed_dict['height'] = None
|
||||
|
||||
# Create database record
|
||||
embed, created = Embed.objects.get_or_create(
|
||||
url=url,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,20 @@ class TestEmbeds(TestCase):
|
|||
def setUp(self):
|
||||
self.hit_count = 0
|
||||
|
||||
def dummy_finder(self, url, max_width=None):
|
||||
# Up hit count
|
||||
self.hit_count += 1
|
||||
|
||||
# Return a pretend record
|
||||
return {
|
||||
'title': "Test: " + url,
|
||||
'type': 'video',
|
||||
'thumbnail_url': '',
|
||||
'width': max_width if max_width else 640,
|
||||
'height': 480,
|
||||
'html': "<p>Blah blah blah</p>",
|
||||
}
|
||||
|
||||
def test_get_embed(self):
|
||||
embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_finder)
|
||||
|
||||
|
|
@ -31,20 +45,23 @@ class TestEmbeds(TestCase):
|
|||
embed = get_embed('www.test.com/4321', finder=self.dummy_finder)
|
||||
self.assertEqual(self.hit_count, 3)
|
||||
|
||||
def dummy_finder(self, url, max_width=None):
|
||||
# Up hit count
|
||||
self.hit_count += 1
|
||||
|
||||
# Return a pretend record
|
||||
def dummy_finder_invalid_width(self, url, max_width=None):
|
||||
# Return a record with an invalid width
|
||||
return {
|
||||
'title': "Test: " + url,
|
||||
'type': 'video',
|
||||
'thumbnail_url': '',
|
||||
'width': max_width if max_width else 640,
|
||||
'width': '100%',
|
||||
'height': 480,
|
||||
'html': "<p>Blah blah blah</p>",
|
||||
}
|
||||
|
||||
def test_invalid_width(self):
|
||||
embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_finder_invalid_width)
|
||||
|
||||
# Width must be set to None
|
||||
self.assertEqual(embed.width, None)
|
||||
|
||||
|
||||
class TestChooser(TestCase):
|
||||
def setUp(self):
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue