Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CLI to support PyYAML 5.1 #806

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/change_log/release-3.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The following new features have been included in the release:

The following bug fixes are included in the 3.1 release:

* Update CLI to support PyYAML 5.1.
* Overlapping raw HTML matches no longer leave placeholders behind (#458).
* Emphasis patterns now recognize newline characters as whitespace (#783).
* Version format had been updated to be PEP 440 compliant (#736).
Expand Down
14 changes: 11 additions & 3 deletions markdown/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@
import warnings
import markdown
try:
import yaml
# We use `unsafe_load` because users may need to pass in actual Python
# objects. As this is only available from the CLI, the user has much
# worse problems if an attacker can use this as an attach vector.
from yaml import unsafe_load as yaml_load
except ImportError: # pragma: no cover
import json as yaml
try:
# Fall back to PyYAML <5.1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should point out that we don't list PyYAML as a dependency, so we can't force a required version. The way it works is that we support both YAML and JSON. If the PyYAML lib is installed, the user may use a either a JSON or YAML config file, either of which is parsed by PyYAML. But if PyYAML is not installed, then the user may only use a JSON config file which is parsed by the json lib in the Python Standard Library.

from yaml import load as yaml_load
except ImportError:
# Fall back to JSON
from json import load as yaml_load

import logging
from logging import DEBUG, WARNING, CRITICAL
Expand Down Expand Up @@ -97,7 +105,7 @@ def parse_options(args=None, values=None):
options.configfile, mode="r", encoding=options.encoding
) as fp:
try:
extension_configs = yaml.load(fp)
extension_configs = yaml_load(fp)
except Exception as e:
message = "Failed parsing extension config file: %s" % \
options.configfile
Expand Down