Update extension regex to match URI fragments (#264)
This commit is contained in:
parent
ab7a0f6a51
commit
59ab5d8777
2 changed files with 3 additions and 1 deletions
|
@ -64,7 +64,7 @@ class Resource:
|
||||||
self.hash = hashlib.md5(self.content)
|
self.hash = hashlib.md5(self.content)
|
||||||
|
|
||||||
def _determine_extension(self) -> Optional[str]:
|
def _determine_extension(self) -> Optional[str]:
|
||||||
extension_pattern = re.compile(r'.*(\..{3,5})(?:\?.*)?$')
|
extension_pattern = re.compile(r'.*(\..{3,5})(?:\?.*)?(?:#.*)?$')
|
||||||
match = re.search(extension_pattern, self.url)
|
match = re.search(extension_pattern, self.url)
|
||||||
if match:
|
if match:
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
|
|
|
@ -15,6 +15,8 @@ from bdfr.resource import Resource
|
||||||
('https://www.resource.com/test/example.jpg', '.jpg'),
|
('https://www.resource.com/test/example.jpg', '.jpg'),
|
||||||
('hard.png.mp4', '.mp4'),
|
('hard.png.mp4', '.mp4'),
|
||||||
('https://preview.redd.it/7zkmr1wqqih61.png?width=237&format=png&auto=webp&s=19de214e634cbcad99', '.png'),
|
('https://preview.redd.it/7zkmr1wqqih61.png?width=237&format=png&auto=webp&s=19de214e634cbcad99', '.png'),
|
||||||
|
('test.jpg#test','.jpg'),
|
||||||
|
('test.jpg?width=247#test','.jpg'),
|
||||||
))
|
))
|
||||||
def test_resource_get_extension(test_url: str, expected: str):
|
def test_resource_get_extension(test_url: str, expected: str):
|
||||||
test_resource = Resource(MagicMock(), test_url)
|
test_resource = Resource(MagicMock(), test_url)
|
||||||
|
|
Loading…
Reference in a new issue