fetch news: handle data: URLs

This commit is contained in:
Kovid Goyal 2024-04-29 08:17:04 +05:30
parent 9e99606c64
commit 6c0edaf1d5
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -17,6 +17,7 @@ import sys
import threading
import time
import traceback
from base64 import standard_b64decode
from urllib.request import urlopen
from calibre import browser, relpath, unicode_path
@ -248,13 +249,18 @@ class RecursiveFetcher:
ans = response(q)
ans.newurl = url
return ans
self.log.debug('Fetching', url)
st = time.monotonic()
is_data_url = url.startswith('data:')
if not is_data_url:
self.log.debug('Fetching', url)
# Check for a URL pointing to the local filesystem and special case it
# for efficiency and robustness. Bypasses delay checking as it does not
# apply to local fetches. Ensures that unicode paths that are not
# representable in the filesystem_encoding work.
if is_data_url:
payload = url.partition(',')[2]
return standard_b64decode(payload)
is_local = 0
if url.startswith('file://'):
is_local = 7