mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #3860: Remote image URIs without filename break builders not supported remote images
This commit is contained in:
parent
8f8f0fb868
commit
ea87cfba4f
2
CHANGES
2
CHANGES
@ -39,6 +39,8 @@ Bugs fixed
|
|||||||
``sphinx.util.compat.Directive``
|
``sphinx.util.compat.Directive``
|
||||||
* #3874: Bogus warnings for "citation not referenced" for cross-file citations
|
* #3874: Bogus warnings for "citation not referenced" for cross-file citations
|
||||||
* #3860: Don't download images when builders not supported images
|
* #3860: Don't download images when builders not supported images
|
||||||
|
* #3860: Remote image URIs without filename break builders not supported remote
|
||||||
|
images
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -20,7 +20,7 @@ from sphinx.transforms import SphinxTransform
|
|||||||
from sphinx.util import logging, requests
|
from sphinx.util import logging, requests
|
||||||
from sphinx.util import epoch_to_rfc1123, rfc1123_to_epoch
|
from sphinx.util import epoch_to_rfc1123, rfc1123_to_epoch
|
||||||
from sphinx.util.images import guess_mimetype, get_image_extension, parse_data_uri
|
from sphinx.util.images import guess_mimetype, get_image_extension, parse_data_uri
|
||||||
from sphinx.util.osutil import ensuredir
|
from sphinx.util.osutil import ensuredir, movefile
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# For type annotation
|
||||||
@ -69,6 +69,8 @@ class ImageDownloader(BaseImageConverter):
|
|||||||
basename = os.path.basename(node['uri'])
|
basename = os.path.basename(node['uri'])
|
||||||
if '?' in basename:
|
if '?' in basename:
|
||||||
basename = basename.split('?')[0]
|
basename = basename.split('?')[0]
|
||||||
|
if basename == '':
|
||||||
|
basename = sha1(node['uri']).hexdigest()
|
||||||
dirname = node['uri'].replace('://', '/').translate({ord("?"): u"/",
|
dirname = node['uri'].replace('://', '/').translate({ord("?"): u"/",
|
||||||
ord("&"): u"/"})
|
ord("&"): u"/"})
|
||||||
ensuredir(os.path.join(self.imagedir, dirname))
|
ensuredir(os.path.join(self.imagedir, dirname))
|
||||||
@ -96,6 +98,14 @@ class ImageDownloader(BaseImageConverter):
|
|||||||
os.utime(path, (timestamp, timestamp))
|
os.utime(path, (timestamp, timestamp))
|
||||||
|
|
||||||
mimetype = guess_mimetype(path, default='*')
|
mimetype = guess_mimetype(path, default='*')
|
||||||
|
if mimetype != '*' and os.path.splitext(basename)[1] == '':
|
||||||
|
# append a suffix if URI does not contain suffix
|
||||||
|
ext = get_image_extension(mimetype)
|
||||||
|
newpath = os.path.join(self.imagedir, dirname, basename + ext)
|
||||||
|
movefile(path, newpath)
|
||||||
|
self.app.env.original_image_uri.pop(path)
|
||||||
|
self.app.env.original_image_uri[newpath] = node['uri']
|
||||||
|
path = newpath
|
||||||
node['candidates'].pop('?')
|
node['candidates'].pop('?')
|
||||||
node['candidates'][mimetype] = path
|
node['candidates'][mimetype] = path
|
||||||
node['uri'] = path
|
node['uri'] = path
|
||||||
|
Loading…
Reference in New Issue
Block a user