1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Fix for bad path encoding

This commit is contained in:
spl0k 2020-04-13 16:08:47 +02:00 committed by Alban Féron
parent f7ecf08bf2
commit 7417766ac5
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
3 changed files with 54 additions and 0 deletions

View File

@ -207,6 +207,12 @@ class Scanner(Thread):
basename = path_or_direntry.name
stat = path_or_direntry.stat()
try:
path.encode("utf-8") # Test for badly encoded paths
except UnicodeError:
self.__stats.errors.append(path)
return
mtime = int(stat.st_mtime)
size = stat.st_size

View File

@ -15,6 +15,7 @@ from . import managers
from . import api
from . import frontend
from .issue85 import Issue85TestCase
from .issue101 import Issue101TestCase
from .issue129 import Issue129TestCase
from .issue133 import Issue133TestCase
@ -29,6 +30,7 @@ def suite():
suite.addTest(managers.suite())
suite.addTest(api.suite())
suite.addTest(frontend.suite())
suite.addTest(unittest.makeSuite(Issue85TestCase))
suite.addTest(unittest.makeSuite(Issue101TestCase))
suite.addTest(unittest.makeSuite(Issue129TestCase))
suite.addTest(unittest.makeSuite(Issue133TestCase))

46
tests/issue85.py Normal file
View File

@ -0,0 +1,46 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2020 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
import os
import os.path
import shutil
import tempfile
import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database
from supysonic.managers.folder import FolderManager
from supysonic.scanner import Scanner
class Issue85TestCase(unittest.TestCase):
def setUp(self):
self.__dir = tempfile.mkdtemp()
init_database("sqlite:")
with db_session:
FolderManager.add("folder", self.__dir)
def tearDown(self):
release_database()
shutil.rmtree(self.__dir)
def test_issue(self):
os.mkdir(os.path.join(self.__dir.encode(), b"\xe6"))
shutil.copyfile(
"tests/assets/folder/silence.mp3",
os.path.join(self.__dir.encode(), b"\xe6", b"silence.mp3"),
)
with db_session:
scanner = Scanner()
scanner.queue_folder("folder")
scanner.run()
if __name__ == "__main__":
unittest.main()