Merge pull request #1946 from lbryio/file-type-fix

lowercase/stripped comparison for known types
This commit is contained in:
Jack Robison 2019-02-22 13:07:09 -05:00 committed by GitHub
commit faa1935203
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View file

@ -155,6 +155,6 @@ types_map = {
def guess_media_type(path): def guess_media_type(path):
_, ext = os.path.splitext(path) _, ext = os.path.splitext(path)
return types_map.get( return types_map.get(
ext, ext.strip().lower(),
'application/octet-stream' if not (ext and ext[1:].strip()) else f'application/x-ext-{ext[1:].strip().lower()}' 'application/octet-stream' if not (ext and ext[1:].strip()) else f'application/x-ext-{ext[1:].strip().lower()}'
) )

View file

@ -5,9 +5,11 @@ from lbrynet.extras.daemon import mime_types
class TestMimeTypes(unittest.TestCase): class TestMimeTypes(unittest.TestCase):
def test_mp4_video(self): def test_mp4_video(self):
self.assertEqual("video/mp4", mime_types.guess_media_type("test.mp4")) self.assertEqual("video/mp4", mime_types.guess_media_type("test.mp4"))
self.assertEqual("video/mp4", mime_types.guess_media_type("test.MP4"))
def test_x_ext_(self): def test_x_ext_(self):
self.assertEqual("application/x-ext-lbry", mime_types.guess_media_type("test.lbry")) self.assertEqual("application/x-ext-lbry", mime_types.guess_media_type("test.lbry"))
self.assertEqual("application/x-ext-lbry", mime_types.guess_media_type("test.LBRY"))
def test_octet_stream(self): def test_octet_stream(self):
self.assertEqual("application/octet-stream", mime_types.guess_media_type("test.")) self.assertEqual("application/octet-stream", mime_types.guess_media_type("test."))