Add missing alt attribute to image tags

This commit is contained in:
Andreas Bernacca 2019-05-13 19:48:43 +02:00 committed by Thibaud Colas
parent aaf0f50c9c
commit 5fef1da5eb
6 changed files with 8 additions and 8 deletions

View file

@ -52,7 +52,7 @@ class EmbedlyFinder(EmbedFinder):
# Convert photos into HTML
if oembed['type'] == 'photo':
html = '<img src="%s" />' % (oembed['url'], )
html = '<img src="%s" alt="">' % (oembed['url'], )
else:
html = oembed.get('html')

View file

@ -65,7 +65,7 @@ class OEmbedFinder(EmbedFinder):
# Convert photos into HTML
if oembed['type'] == 'photo':
html = '<img src="%s" />' % (oembed['url'], )
html = '<img src="%s" alt="">' % (oembed['url'], )
else:
html = oembed.get('html')

View file

@ -259,7 +259,7 @@ class TestEmbedly(TestCase):
oembed.return_value = {'type': 'photo',
'url': 'http://www.example.com'}
result = EmbedlyFinder(key='foo').find_embed('http://www.example.com')
self.assertEqual(result['html'], '<img src="http://www.example.com" />')
self.assertEqual(result['html'], '<img src="http://www.example.com" alt="">')
oembed.return_value = {'type': 'something else',
'html': '<foo>bar</foo>'}
@ -325,7 +325,7 @@ class TestOembed(TestCase):
'url': 'http://www.example.com'}
result = OEmbedFinder().find_embed("http://www.youtube.com/watch/")
self.assertEqual(result['type'], 'photo')
self.assertEqual(result['html'], '<img src="http://www.example.com" />')
self.assertEqual(result['html'], '<img src="http://www.example.com" alt="">')
loads.assert_called_with("foo")
@patch('urllib.request.urlopen')

View file

@ -23,7 +23,7 @@ class ImageEmbedHandler(EmbedHandler):
try:
image = cls.get_instance(attrs)
except ObjectDoesNotExist:
return "<img>"
return '<img alt="">'
image_format = get_image_format(attrs['format'])
return image_format.image_to_html(image, attrs.get('alt', ''))

View file

@ -36,7 +36,7 @@ class ImageEmbedHandler:
try:
image = Image.objects.get(id=attrs['id'])
except Image.DoesNotExist:
return "<img>"
return '<img alt="">'
image_format = get_image_format(attrs['format'])

View file

@ -44,7 +44,7 @@ class TestEditorHtmlImageEmbedHandler(TestCase, WagtailTestUtils):
def test_expand_db_attributes_for_editor_nonexistent_image(self):
self.assertEqual(
EditorHtmlImageEmbedHandler.expand_db_attributes({'id': 0}),
'<img>'
'<img alt="">'
)
def test_expand_db_attributes_for_editor_escapes_alt_text(self):
@ -96,7 +96,7 @@ class TestFrontendImageEmbedHandler(TestCase, WagtailTestUtils):
def test_expand_db_attributes_for_frontend_with_nonexistent_image(self):
result = FrontendImageEmbedHandler.expand_db_attributes({'id': 0})
self.assertEqual(result, '<img>')
self.assertEqual(result, '<img alt="">')
def test_expand_db_attributes_for_frontend_escapes_alt_text(self):
Image.objects.create(id=1, title='Test', file=get_test_image_file())