From 060041a69e4646b87dec85e0125f6d8a41648152 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Wed, 17 May 2017 10:19:18 -0400 Subject: [PATCH 1/2] Load YAML as binary data This lets the YAML library itself deal with the encoding (mostly), which should address #2456 and #2565, which have to do with `open` giving us a system-specific encoding by default on Python 3 on Windows when the files should have been written using UTF-8 per the YAML standard. --- beets/util/confit.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/beets/util/confit.py b/beets/util/confit.py index 373e05ffc..73ae97abc 100644 --- a/beets/util/confit.py +++ b/beets/util/confit.py @@ -668,7 +668,7 @@ def load_yaml(filename): parsed, a ConfigReadError is raised. """ try: - with open(filename, 'r') as f: + with open(filename, 'rb') as f: return yaml.load(f, Loader=Loader) except (IOError, yaml.error.YAMLError) as exc: raise ConfigReadError(filename, exc) @@ -908,9 +908,10 @@ class Configuration(RootView): default_source = source break if default_source and default_source.filename: - with open(default_source.filename, 'r') as fp: + with open(default_source.filename, 'rb') as fp: default_data = fp.read() - yaml_out = restore_yaml_comments(yaml_out, default_data) + yaml_out = restore_yaml_comments(yaml_out, + default_data.decode('utf8')) return yaml_out From 35dd6fdf217aca5f2685df9a379ff79f238d396e Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Wed, 17 May 2017 10:22:44 -0400 Subject: [PATCH 2/2] Changelog for #2566 --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 9caca1280..caea9c6a4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -107,6 +107,8 @@ Fixes: * :doc:`/plugins/web`: Avoid a crash when sending binary data, such as Chromaprint fingerprints, in music attributes. :bug:`2542` :bug:`2532` * Fix a hang when parsing templates that end in newlines. :bug:`2562` +* Fix a crash when reading non-ASCII characters in configuration files on + Windows under Python 3. :bug:`2456` :bug:`2565` :bug:`2566` Two plugins had backends removed due to bitrot: