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

Images with query strings are given the wrong extension #53

Closed
alecgibson opened this issue Mar 20, 2018 · 3 comments
Closed

Images with query strings are given the wrong extension #53

alecgibson opened this issue Mar 20, 2018 · 3 comments

Comments

@alecgibson
Copy link

When epub-gen is provided an img with a src with a query string, then the image's extension is incorrectly changed to .bin.

For example:

<img src="http://example.com/image.jpg?w=400">

I believe the bit of the code to blame is here, where the mime package returns:

mime.lookup("http://example.com/image.jpg")       // => "image/jpeg"
mime.lookup("http://example.com/image.jpg?w=400") // => "application/octet-stream"

mime.extension("image/jpeg")                      // => "jpeg"
mime.extension("application/octet-stream")        // => "bin"

We can try to strip the query string at our end, but sometimes query strings are used to contain options for how the image is rendered (a common example being Gravatar).

It would be best if epub-gen stripped the query string when trying to determine the mediaType and extension.

@pedrosanta
Copy link
Collaborator

Nice catch @alecgibson. 👍 Yep, I say strip the query string from the image URL, and then mime would work well, I suppose. I can put up a PR, along with another one for #52, as soon as possible.

@pedrosanta
Copy link
Collaborator

pedrosanta commented Mar 23, 2018

It would be best if epub-gen stripped the query string when trying to determine the mediaType and extension.

Yep, just checked out on mime package and it really doesn't support URL with query strings (check broofa/mime#131)(1), so, agreed, better to update the lib to remove/ignore the query string before checking the mime types/extension.

Coming right up!

(1) - The mime lib seems more oriented to file paths and all, and author prefers that responsibility to lie outside the mime lib so, no point raising an issue there/upstream I suppose. 🙂

@pedrosanta
Copy link
Collaborator

Fixed on v0.0.19. Closing.

zbrongyaozb pushed a commit to zbrongyaozb/epub-gen that referenced this issue Aug 2, 2022
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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

No branches or pull requests

2 participants