Don't urllib.unquote when using requests (#2943)

This commit is contained in:
Viktor Ricci 2024-01-19 07:09:13 +01:00 committed by GitHub
parent fe5ba1cce7
commit fd685f29fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -911,21 +911,18 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
def _retrieveURL(self, url: str) -> str | None:
"Download file into media folder and return local filename or None."
# urllib doesn't understand percent-escaped utf8, but requires things like
# '#' to be escaped.
url = urllib.parse.unquote(url)
if url.lower().startswith("file://"):
url = url.replace("%", "%25")
url = url.replace("#", "%23")
local = True
else:
local = False
local = url.lower().startswith("file://")
# fetch it into a temporary folder
self.mw.progress.start(immediate=not local, parent=self.parentWindow)
content_type = None
error_msg: str | None = None
try:
if local:
# urllib doesn't understand percent-escaped utf8, but requires things like
# '#' to be escaped.
url = urllib.parse.unquote(url)
url = url.replace("%", "%25")
url = url.replace("#", "%23")
req = urllib.request.Request(
url, None, {"User-Agent": "Mozilla/5.0 (compatible; Anki)"}
)