Skip to content

Commit

Permalink
Escape image filenames
Browse files Browse the repository at this point in the history
Without this change, local images with `#` in their name result in incorrect URLs

There is already a similar call to `urllib.parse.quote` for file downloads, suggesting this is a sensible approach.
  • Loading branch information
eric-wieser committed Mar 16, 2022
1 parent 37e8967 commit 68ef3ed
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sphinx/writers/html.py
Expand Up @@ -612,7 +612,7 @@ def visit_image(self, node: Element) -> None:
# rewrite the URI if the environment knows about it
if olduri in self.builder.images:
node['uri'] = posixpath.join(self.builder.imgpath,
self.builder.images[olduri])
urllib.parse.quote(self.builder.images[olduri]))

if 'scale' in node:
# Try to figure out image height and width. Docutils does that too,
Expand Down
2 changes: 1 addition & 1 deletion sphinx/writers/html5.py
Expand Up @@ -560,7 +560,7 @@ def visit_image(self, node: Element) -> None:
# rewrite the URI if the environment knows about it
if olduri in self.builder.images:
node['uri'] = posixpath.join(self.builder.imgpath,
self.builder.images[olduri])
urllib.parse.quote(self.builder.images[olduri]))

if 'scale' in node:
# Try to figure out image height and width. Docutils does that too,
Expand Down

0 comments on commit 68ef3ed

Please sign in to comment.