From 0e20770cc3ffa56d6466d9df8faae215dcdd6773 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Thu, 19 Nov 2015 15:38:20 -0800 Subject: [PATCH] Convert YAML keys and values back to strings I hadn't quite realized before that the user could also change the *keys* to be non-strings too! This also prevents against that by just reinterpreting everything as strings. --- beetsplug/edit.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/beetsplug/edit.py b/beetsplug/edit.py index 9b86ca94a..f1cf85095 100644 --- a/beetsplug/edit.py +++ b/beetsplug/edit.py @@ -52,7 +52,8 @@ def dump(arg): def load(s): - """Read a sequence of YAML documents back to a list of dictionaries. + """Read a sequence of YAML documents back to a list of dictionaries + with string keys and values. Can raise a `ParseError`. """ @@ -65,7 +66,12 @@ def load(s): type(d).__name__ ) ) - out.append(d) + + # Convert all keys and values to strings. They started out + # as strings, but the user may have inadvertently messed + # this up. + out.append({unicode(k): unicode(v) for k, v in d.items()}) + except yaml.YAMLError as e: raise ParseError('invalid YAML: {}'.format(e)) return out