jimporter / mike

Manage multiple versions of your MkDocs-powered documentation via Git
BSD 3-Clause "New" or "Revised" License
536 stars 47 forks source link

Error while deploying with emoji.twemoji #24

Closed JulioV closed 3 years ago

JulioV commented 3 years ago

I found the following error while trying to deploy a site with pymdownx.emoji extension enabled, python 3.7.3 and mike 0.5.3 on MacOS 10.15.7:

mike: could not determine a constructor for the tag 'tag:yaml.org,2002:python/name:materialx.emoji.twemoji'

The minimal reproducible example is a site with the following mkdocs.yaml

site_name: Test
markdown_extensions:
    - pymdownx.emoji:
        emoji_index: !!python/name:materialx.emoji.twemoji
        emoji_generator: !!python/name:materialx.emoji.to_svg
nav:
  - Home: 'index.md'
jimporter commented 3 years ago

This is because mike uses safe_load to load YAML files, so as to prevent people from doing malicious things with them. That's probably not very useful though, since it seems MkDocs doesn't use safe_load. If you replace safe_load with load here, does it work?

https://github.com/jimporter/mike/blob/3ce1a8c92c296bf9a1f0c5419def85658eb3a2f5/mike/mkdocs.py#L9

JulioV commented 3 years ago

It does work!

jimporter commented 3 years ago

Awesome! I'll commit a change with that fix and publish a quick hotfix to PyPI shortly...

JulioV commented 3 years ago

Just so you know, you get the following warning:

The default 'Loader' for 'load(stream)' without further arguments can be unsafe.
Use 'load(stream, Loader=ruamel.yaml.Loader)' explicitly if that is OK.
Alternatively include the following in your code:

  import warnings
  warnings.simplefilter('ignore', ruamel.yaml.error.UnsafeLoaderWarning)

In most other cases you should consider using 'safe_load(stream)'
  config = yaml.load(f)
jimporter commented 3 years ago

Ah, right. I forgot about that...

This should all be working correctly in 64807ea58db41d7002c911cab2b665ac91c8e1d8 and published on PyPI at https://pypi.org/project/mike/0.5.5/

Thanks for catching this (and the warning message)!