Skip to content

Commit

Permalink
Merge pull request #3700 from theacodes/fix-3699
Browse files Browse the repository at this point in the history
Fix crash when mkdocs_theme.yml is empty
  • Loading branch information
tomchristie committed May 10, 2024
2 parents 30e8142 + cd80116 commit fb1d106
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions mkdocs/tests/theme_tests.py
Expand Up @@ -104,3 +104,22 @@ def test_inherited_theme(self):
],
)
self.assertEqual(theme.static_templates, {'sitemap.xml', 'child.html', 'parent.html'})

def test_empty_config_file(self):
# Test for themes with *empty* mkdocs_theme.yml.
# See https://github.com/mkdocs/mkdocs/issues/3699
m = mock.Mock(
# yaml.load returns "None" for an empty file
side_effect=[None]
)
with mock.patch('yaml.load', m) as m:
theme = Theme(name='mkdocs')
# Should only have the default name and locale __vars set in
# Theme.__init__()
self.assertEqual(
dict(theme),
{
'name': 'mkdocs',
'locale': parse_locale('en'),
},
)
3 changes: 3 additions & 0 deletions mkdocs/theme.py
Expand Up @@ -138,6 +138,9 @@ def _load_theme_config(self, name: str) -> None:
f"Please upgrade to a current version of the theme."
)

if theme_config is None:
theme_config = {}

log.debug(f"Loaded theme configuration for '{name}' from '{file_path}': {theme_config}")

if parent_theme := theme_config.pop('extends', None):
Expand Down

0 comments on commit fb1d106

Please sign in to comment.