From 0d1fa8065155392b3fc3066a0e253785a8eadcd6 Mon Sep 17 00:00:00 2001 From: Bruno Cauet Date: Wed, 14 Jan 2015 12:21:05 +0100 Subject: [PATCH] Smartplaylist: don't utf8-encode the name A Template expression expects an unicode, not an utf8-encoded string. Add a test for that. --- beetsplug/smartplaylist.py | 3 +-- test/test_template.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/beetsplug/smartplaylist.py b/beetsplug/smartplaylist.py index 4c242efe6..3b5be2149 100644 --- a/beetsplug/smartplaylist.py +++ b/beetsplug/smartplaylist.py @@ -76,11 +76,10 @@ class SmartPlaylistPlugin(BeetsPlugin): items.extend(_items_for_query(lib, playlist['query'], False)) m3us = {} - basename = playlist['name'].encode('utf8') # As we allow tags in the m3u names, we'll need to iterate through # the items and generate the correct m3u file names. for item in items: - m3u_name = item.evaluate_template(basename, True) + m3u_name = item.evaluate_template(playlist['name'], True) if m3u_name not in m3us: m3us[m3u_name] = [] item_path = item.path diff --git a/test/test_template.py b/test/test_template.py index 1bc0b2cd7..20c0df8f4 100644 --- a/test/test_template.py +++ b/test/test_template.py @@ -1,3 +1,4 @@ +# -*- coding: utf8 -*- # This file is part of beets. # Copyright 2015, Adrian Sampson. # @@ -14,6 +15,8 @@ """Tests for template engine. """ +import warnings + from _common import unittest from beets.util import functemplate @@ -207,6 +210,13 @@ class ParseTest(unittest.TestCase): self._assert_call(arg_parts[0], u"bar", 1) self.assertEqual(list(_normexpr(arg_parts[0].args[0])), [u'baz']) + def test_fail_on_utf8(self): + parts = u'é'.encode('utf8') + warnings.simplefilter("ignore") + with self.assertRaises(UnicodeDecodeError): + functemplate._parse(parts) + warnings.simplefilter("default") + class EvalTest(unittest.TestCase): def _eval(self, template):