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

Image src URLs with spaces in them don't work for fittedImage and croppedImage #221

Closed
srikumarks opened this Issue Apr 21, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@srikumarks

srikumarks commented Apr 21, 2015

In the Graphics.Element package, fittedImage and croppedImage don't work for all image URLs.

For example, if an image URL is "somewhere/my cool photo.jpg", the image won't show up with fittedImage and croppedImage. It will, however, show up when you use "image" or "tiledImage", or if the image was named "somewhere/my-cool-photo.jpg" (without spaces).

srikumarks added a commit to srikumarks/elm-core that referenced this issue Apr 21, 2015

Fixed #221 - Image src URLs with spaces in them don't work for fitted…
…Image and croppedImage

The problem was that the native implementations of `fittedImage` and
`croppedImage` used CSS `background-image`, but were not encoding the
URLs before generating the property. This commit encodes the `src`
parameter using `encodeURIComponent`, which makes them work correctly.

srikumarks added a commit to srikumarks/elm-core that referenced this issue Apr 21, 2015

srikumarks added a commit to srikumarks/elm-core that referenced this issue Apr 26, 2015

For #221 - Added encodeURI and family of functions to Basics so that
they can be used to make hrefs correctly in Graphics.Element.

srikumarks added a commit to srikumarks/elm-core that referenced this issue Apr 26, 2015

For #221 - Added encodeURI and family of functions to Basics so that
they can be used to make hrefs correctly in Graphics.Element.

srikumarks added a commit to srikumarks/elm-core that referenced this issue Apr 26, 2015

For #221 - The src parameter needs to appear within quotes to work co…
…rrectly in some cases.

For valid URLs with parentheses in them, for example, the fittedImage and tiledImage
functions won't set the correct style. This quotes the result, assuming that src is a
valid URL encoded string. Javascript's encodeURI function escapes double quotes and
can be used to convert things like file paths to href values.
@srikumarks

This comment has been minimized.

Show comment
Hide comment
@srikumarks

srikumarks Apr 26, 2015

Please ignore the first few commits, but the last two are perhaps worth considering. Here is what they solve -

When we provide a "src" string to tiledImage and fittedImage functions (in Graphics.Element), the functions assume that the string contains no parens (which are allowed in hrefs). For example, "helloworld).png" is a valid src value, but will break the url setting code in these two functions. Also, if we pass "hello+world.png", the intention is not clear as to whether we're referring to the local file "hello world.png" or "hello+world.png".

To make these correct, we need access to the encodeURI/decodeURI and encodeURIComponent/decodeURIComponent functions available as globals in Javascript. 2ad079b adds these to Basics and b8a94d0 adds double quotes around the "src" parameters in tiledImage and fittedImage functions.

This, I think, is a useful first step, but requires the developer to ensure correct string encodings. It will be good to have a type to track the encoding status of a string so that such errors are caught by the type system.

srikumarks commented Apr 26, 2015

Please ignore the first few commits, but the last two are perhaps worth considering. Here is what they solve -

When we provide a "src" string to tiledImage and fittedImage functions (in Graphics.Element), the functions assume that the string contains no parens (which are allowed in hrefs). For example, "helloworld).png" is a valid src value, but will break the url setting code in these two functions. Also, if we pass "hello+world.png", the intention is not clear as to whether we're referring to the local file "hello world.png" or "hello+world.png".

To make these correct, we need access to the encodeURI/decodeURI and encodeURIComponent/decodeURIComponent functions available as globals in Javascript. 2ad079b adds these to Basics and b8a94d0 adds double quotes around the "src" parameters in tiledImage and fittedImage functions.

This, I think, is a useful first step, but requires the developer to ensure correct string encodings. It will be good to have a type to track the encoding status of a string so that such errors are caught by the type system.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jan 19, 2016

Contributor

Is this issue completely resolved by #222? Then it would make sense to close the issue itself.

Contributor

jvoigtlaender commented Jan 19, 2016

Is this issue completely resolved by #222? Then it would make sense to close the issue itself.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jul 6, 2016

Contributor

This issue would now belong over at https://github.com/evancz/elm-graphics.

Contributor

jvoigtlaender commented Jul 6, 2016

This issue would now belong over at https://github.com/evancz/elm-graphics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment