Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer MIME type when determining extensions for MediaBag items #10557

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

max-heller
Copy link
Contributor

Currently, remote images added to the MediaBag are stored at paths with extensions determined based on the external URI. For instance, an image from https://example.com/image.png is stored as .png. If the URI does not contain an extension (e.g., https://example.com/image), then the content-type of the downloaded image is used to determine the extension.

This change switches the precedence such that content-type is preferred over extensions contained in the URI. This is necessary because some images are located at URIs with misleading extensions -- shields.io, for instance, serves SVGs from URIs with .yml extensions. With this change, the image/svg+xml content-type is now preferred over the .yml URI extension. This fixes a bug in the PDF writer in which such an image would be mishandled due to not being identified as an SVG.

Closes #10553

Currently, remote images added to the MediaBag are stored at paths with
extensions determined based on the external URI. For instance, an image
from https://example.com/image.png is stored as <hash>.png. If the
URI does not contain an extension (e.g., https://example.com/image),
then the content-type of the downloaded image is used to determine the
extension.

This change switches the precedence such that content-type is preferred
over extensions contained in the URI. This is necessary because some
images are located at URIs with misleading extensions -- shields.io,
for instance, serves SVGs from URIs with .yml extensions. With this
change, the image/svg+xml content-type is now preferred over the .yml
URI extension. This fixes a bug in the PDF writer in which such an image
would be mishandled due to not being identified as an SVG.
@max-heller max-heller force-pushed the mediaitem-extensions branch from 511fcb9 to 6866b43 Compare January 21, 2025 22:40
@jgm jgm merged commit b95645b into jgm:main Jan 22, 2025
10 of 13 checks passed
@jgm
Copy link
Owner

jgm commented Jan 22, 2025

thanks!

@max-heller max-heller deleted the mediaitem-extensions branch January 22, 2025 02:15
max-heller added a commit to max-heller/mdbook-pandoc that referenced this pull request Feb 9, 2025
Removes a workaround for remote images served from URIs without standard
image extensions (e.g., https://img.shields.io/github/actions/workflow/status/rust-lang/mdBook/main.yml
hosts an SVG image despite its YAML extension) since Pandoc implemented
a fix in jgm/pandoc#10557 (released in 3.6.3).
This allows removing the dependency on an HTTP client.
max-heller added a commit to max-heller/mdbook-pandoc that referenced this pull request Feb 9, 2025
Removes a workaround for remote images served from URIs without standard
image extensions (e.g.,
https://img.shields.io/github/actions/workflow/status/rust-lang/mdBook/main.yml
hosts an SVG image despite its YAML extension) since Pandoc implemented
a fix in jgm/pandoc#10557 (released in 3.6.3).
This allows removing the dependency on an HTTP client.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LaTeX writer: remote SVG images with non-.svg URI extensions are not treated as SVGs
2 participants