Skip to content

Commit

Permalink
Log a warning when the HTML reader encounters a nonconformant meta tag
Browse files Browse the repository at this point in the history
Instead of throwing an exception and skipping the HTML file, log a
warning with a message which makes it more obvious as to what happened.
  • Loading branch information
malept committed Nov 8, 2013
1 parent 455c159 commit 35375b1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pelican/readers.py
Expand Up @@ -302,7 +302,12 @@ def build_tag(self, tag, attrs, close_tag):
return result + '>'

def _handle_meta_tag(self, attrs):
name = self._attr_value(attrs, 'name').lower()
name = self._attr_value(attrs, 'name')
if name is None:
attr_serialized = ', '.join(['{}="{}"'.format(k, v) for k, v in attrs])
logger.warning("Meta tag in file %s does not have a 'name' attribute, skipping. Attributes: %s", self._filename, attr_serialized)
return
name = name.lower()
contents = self._attr_value(attrs, 'content', '')
if not contents:
contents = self._attr_value(attrs, 'contents', '')
Expand Down
12 changes: 12 additions & 0 deletions pelican/tests/content/article_with_nonconformant_meta_tags.html
@@ -0,0 +1,12 @@
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Article with Nonconformant HTML meta tags</title>
<meta name="summary" content="Summary and stuff" />
</head>
<body>
Multi-line metadata should be supported
as well as <strong>inline markup</strong>.
</body>
</html>
1 change: 1 addition & 0 deletions pelican/tests/test_generators.py
Expand Up @@ -86,6 +86,7 @@ def test_generate_context(self):
['Test mkd File', 'published', 'test', 'article'],
['This is a super article !', 'published', 'Yeah', 'article'],
['This is a super article !', 'published', 'Yeah', 'article'],
['Article with Nonconformant HTML meta tags', 'published', 'Default', 'article'],
['This is a super article !', 'published', 'yeah', 'article'],
['This is a super article !', 'published', 'yeah', 'article'],
['This is a super article !', 'published', 'yeah', 'article'],
Expand Down
10 changes: 10 additions & 0 deletions pelican/tests/test_readers.py
Expand Up @@ -384,3 +384,13 @@ def test_article_metadata_key_lowercase(self):
self.assertIn('category', page.metadata, 'Key should be lowercase.')
self.assertEqual('Yeah', page.metadata.get('category'),
'Value keeps cases.')

def test_article_with_nonconformant_meta_tags(self):
page = self.read_file(path='article_with_nonconformant_meta_tags.html')
expected = {
'summary': 'Summary and stuff',
'title': 'Article with Nonconformant HTML meta tags',
}

for key, value in expected.items():
self.assertEqual(value, page.metadata[key], key)

0 comments on commit 35375b1

Please sign in to comment.