mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
[3.12] gh-66543: Fix mimetype.guess_type() (GH-117217) (GH-117256)
Fix parsing of the following corner cases:
* URLs with only a host name
* URLs containing a fragment
* URLs containing a query
* filenames with only a UNC sharepoint on Windows
(cherry picked from commit 9654daf793
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
This commit is contained in:
parent
54514467c2
commit
36b1a20851
4 changed files with 45 additions and 9 deletions
|
@ -120,7 +120,13 @@ class MimeTypes:
|
|||
but non-standard types.
|
||||
"""
|
||||
url = os.fspath(url)
|
||||
scheme, url = urllib.parse._splittype(url)
|
||||
p = urllib.parse.urlparse(url)
|
||||
if p.scheme and len(p.scheme) > 1:
|
||||
scheme = p.scheme
|
||||
url = p.path
|
||||
else:
|
||||
scheme = None
|
||||
url = os.path.splitdrive(url)[1]
|
||||
if scheme == 'data':
|
||||
# syntax of data URLs:
|
||||
# dataurl := "data:" [ mediatype ] [ ";base64" ] "," data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue