mirror of
https://github.com/beetbox/beets.git
synced 2026-01-02 14:03:12 +01:00
normalize to NFC on non-Mac platforms (#367)
This commit is contained in:
parent
037f751e23
commit
781c26ffd0
3 changed files with 21 additions and 3 deletions
|
|
@ -807,7 +807,7 @@ class Library(BaseLibrary):
|
|||
self.conn.commit()
|
||||
|
||||
def destination(self, item, pathmod=None, in_album=False,
|
||||
fragment=False, basedir=None):
|
||||
fragment=False, basedir=None, platform=None):
|
||||
"""Returns the path in the library directory designated for item
|
||||
item (i.e., where the file ought to be). in_album forces the
|
||||
item to be treated as part of an album. fragment makes this
|
||||
|
|
@ -817,6 +817,7 @@ class Library(BaseLibrary):
|
|||
directory for the destination.
|
||||
"""
|
||||
pathmod = pathmod or os.path
|
||||
platform = platform or sys.platform
|
||||
|
||||
# Use a path format based on a query, falling back on the
|
||||
# default.
|
||||
|
|
@ -878,7 +879,10 @@ class Library(BaseLibrary):
|
|||
subpath = subpath_tmpl.substitute(mapping, funcs)
|
||||
|
||||
# Encode for the filesystem, dropping unencodable characters.
|
||||
subpath = unicodedata.normalize('NFD', subpath)
|
||||
if platform == 'darwin':
|
||||
subpath = unicodedata.normalize('NFD', subpath)
|
||||
else:
|
||||
subpath = unicodedata.normalize('NFC', subpath)
|
||||
if isinstance(subpath, unicode) and not fragment:
|
||||
encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
|
||||
subpath = subpath.encode(encoding, 'replace')
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ Changelog
|
|||
tracks on the album (to help you guess what might be going wrong).
|
||||
* :doc:`/plugins/bpd`: Use Gstreamer's ``playbin2`` element instead of the
|
||||
deprecated ``playbin``.
|
||||
* Filenames are normalized with Unicode Normal Form D (NFD).
|
||||
* Filenames are normalized with Unicode Normal Form D (NFD) on Mac OS X and NFC
|
||||
on all other platforms.
|
||||
|
||||
|
||||
1.0b13 (March 16, 2012)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import ntpath
|
|||
import posixpath
|
||||
import shutil
|
||||
import re
|
||||
import unicodedata
|
||||
|
||||
import _common
|
||||
from _common import unittest
|
||||
|
|
@ -404,6 +405,18 @@ class DestinationTest(unittest.TestCase):
|
|||
])
|
||||
self.assertEqual(p, 'bar/bar')
|
||||
|
||||
def test_unicode_normalized_nfd_on_mac(self):
|
||||
instr = unicodedata.normalize('NFC', u'caf\xe9')
|
||||
self.lib.path_formats = [('default', instr)]
|
||||
dest = self.lib.destination(self.i, platform='darwin', fragment=True)
|
||||
self.assertEqual(dest, unicodedata.normalize('NFD', instr))
|
||||
|
||||
def test_unicode_normalized_nfc_on_linux(self):
|
||||
instr = unicodedata.normalize('NFD', u'caf\xe9')
|
||||
self.lib.path_formats = [('default', instr)]
|
||||
dest = self.lib.destination(self.i, platform='linux2', fragment=True)
|
||||
self.assertEqual(dest, unicodedata.normalize('NFC', instr))
|
||||
|
||||
class PathFormattingMixin(object):
|
||||
"""Utilities for testing path formatting."""
|
||||
def _setf(self, fmt):
|
||||
|
|
|
|||
Loading…
Reference in a new issue