mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #4688: Error to download remote images having long URL
This commit is contained in:
parent
27abce6306
commit
0eb5e0865a
1
CHANGES
1
CHANGES
@ -27,6 +27,7 @@ Bugs fixed
|
||||
* #4725: Sphinx does not work with python 3.5.0 and 3.5.1
|
||||
* #4716: Generation PDF file with TexLive on Windows, file not found error
|
||||
* #4574: vertical space before equation in latex
|
||||
* #4688: Error to download remote images having long URL
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
@ -30,6 +30,8 @@ if False:
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MAX_FILENAME_LEN = 32
|
||||
|
||||
|
||||
class BaseImageConverter(SphinxTransform):
|
||||
def apply(self):
|
||||
@ -70,10 +72,14 @@ class ImageDownloader(BaseImageConverter):
|
||||
basename = os.path.basename(node['uri'])
|
||||
if '?' in basename:
|
||||
basename = basename.split('?')[0]
|
||||
if basename == '':
|
||||
basename = sha1(node['uri'].encode("utf-8")).hexdigest()
|
||||
if basename == '' or len(basename) > MAX_FILENAME_LEN:
|
||||
filename, ext = os.path.splitext(node['uri'])
|
||||
basename = sha1(filename.encode("utf-8")).hexdigest() + ext
|
||||
|
||||
dirname = node['uri'].replace('://', '/').translate({ord("?"): u"/",
|
||||
ord("&"): u"/"})
|
||||
if len(dirname) > MAX_FILENAME_LEN:
|
||||
dirname = sha1(dirname.encode('utf-8')).hexdigest()
|
||||
ensuredir(os.path.join(self.imagedir, dirname))
|
||||
path = os.path.join(self.imagedir, dirname, basename)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user