Fix local file download by encoding URL

Properly encode links to files with special characters for the user to
actually be able to download them.

The issue still remains for image files but the logic path
is quite different than with other files fix might involve changes
to docutils.

Fixes sphinx-doc/sphinx#3097

Signed-off-by: Johannes Aalto <ext-johannes.aalto@vaisala.com>
This commit is contained in:
Johannes Aalto 2021-09-15 09:30:04 +03:00
parent fa3b334ed0
commit b2bd115dc8
2 changed files with 6 additions and 2 deletions

View File

@ -12,6 +12,7 @@ import copy
import os
import posixpath
import re
import urllib.parse
import warnings
from typing import TYPE_CHECKING, Iterable, Tuple, cast
@ -589,7 +590,8 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator):
self.context.append('</a>')
elif 'filename' in node:
atts['class'] += ' internal'
atts['href'] = posixpath.join(self.builder.dlpath, node['filename'])
atts['href'] = posixpath.join(self.builder.dlpath,
urllib.parse.quote(node['filename']))
self.body.append(self.starttag(node, 'a', '', **atts))
self.context.append('</a>')
else:

View File

@ -11,6 +11,7 @@
import os
import posixpath
import re
import urllib.parse
import warnings
from typing import TYPE_CHECKING, Iterable, Tuple, cast
@ -529,7 +530,8 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
self.context.append('</a>')
elif 'filename' in node:
atts['class'] += ' internal'
atts['href'] = posixpath.join(self.builder.dlpath, node['filename'])
atts['href'] = posixpath.join(self.builder.dlpath,
urllib.parse.quote(node['filename']))
self.body.append(self.starttag(node, 'a', '', **atts))
self.context.append('</a>')
else: