Repository: getpelican/pelican

Issue:
Empty alt attribute for image warning includes HTML
When using reStructuredText image tags with width and height without an alt tag, the warning will include the raw HTML. See the result below.

``` rst
.. image:: /images/versioning-with-xcode.png
    :width: 671px
    :height: 563px
    :align: center
```
### Actual result

```
WARNING: Empty alt attribute for image versioning-with-xcode.png" style="width: 671px; height: 563px; in /Users/kylef/Projects/kylef/kylefuller.co.uk/content/posts/versioning-with-xcode-and-git.rst
```
### Expected result

```
WARNING: Empty alt attribute for image versioning-with-xcode.png in /Users/kylef/Projects/kylef/kylefuller.co.uk/content/posts/versioning-with-xcode-and-git.rst
```

Empty alt attribute for image warning includes HTML
When using reStructuredText image tags with width and height without an alt tag, the warning will include the raw HTML. See the result below.

``` rst
.. image:: /images/versioning-with-xcode.png
    :width: 671px
    :height: 563px
    :align: center
```
### Actual result

```
WARNING: Empty alt attribute for image versioning-with-xcode.png" style="width: 671px; height: 563px; in /Users/kylef/Projects/kylef/kylefuller.co.uk/content/posts/versioning-with-xcode-and-git.rst
```
### Expected result

```
WARNING: Empty alt attribute for image versioning-with-xcode.png in /Users/kylef/Projects/kylef/kylefuller.co.uk/content/posts/versioning-with-xcode-and-git.rst
```



Discussion:
@kylef: Does the fix provided by @storeyio satisfactorily address the issue you reported here?

Awesome, thanks @storeyio.

@kylef: Does the fix provided by @storeyio satisfactorily address the issue you reported here?

Awesome, thanks @storeyio.


Resolving patch:
diff --git a/pelican/readers.py b/pelican/readers.py
--- a/pelican/readers.py
+++ b/pelican/readers.py
@@ -584,7 +584,7 @@ def find_empty_alt(content, path):
             # src before alt
             <img
             [^\>]*
-            src=(['"])(.*)\1
+            src=(['"])(.*?)\1
             [^\>]*
             alt=(['"])\3
         )|(?:
@@ -593,7 +593,7 @@ def find_empty_alt(content, path):
             [^\>]*
             alt=(['"])\4
             [^\>]*
-            src=(['"])(.*)\5
+            src=(['"])(.*?)\5
         )
         """, re.X)
     for match in re.findall(imgs, content):


Test patch:
diff --git a/pelican/tests/test_readers.py b/pelican/tests/test_readers.py
--- a/pelican/tests/test_readers.py
+++ b/pelican/tests/test_readers.py
@@ -9,6 +9,13 @@
 from pelican.tests.support import get_settings, unittest
 from pelican.utils import SafeDatetime
 
+try:
+    from unittest.mock import patch
+except ImportError:
+    try:
+        from mock import patch
+    except ImportError:
+        patch = False
 
 CUR_DIR = os.path.dirname(__file__)
 CONTENT_PATH = os.path.join(CUR_DIR, 'content')
@@ -81,6 +88,22 @@ def test_readfile_unknown_extension(self):
         with self.assertRaises(TypeError):
             self.read_file(path='article_with_metadata.unknownextension')
 
+    @unittest.skipUnless(patch, 'Needs Mock module')
+    def test_find_empty_alt(self):
+        with patch('pelican.readers.logger') as log_mock:
+            content = ['<img alt="" src="test-image.png" width="300px" />',
+                       '<img src="test-image.png"  width="300px" alt="" />']
+
+            for tag in content:
+                readers.find_empty_alt(tag, '/test/path')
+                log_mock.warning.assert_called_with(
+                    u'Empty alt attribute for image %s in %s',
+                    u'test-image.png',
+                    u'/test/path',
+                    extra={'limit_msg':
+                           'Other images have empty alt attributes'}
+                )
+
 
 class RstReaderTest(ReaderTest):