amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

AMP-Carousel - Unable to load image in gallery when the original img contains spaces

Open merakmarey opened this issue 7 years ago • 12 comments

Image show as missing on gallery mode if file name is duplicated, even if path is different.

Image sources on carousel:

/i/images/4/image-1.jpg /i/images/5/image-1.jpg

Error arrives when setting srcset attribute, the first image will be set to "/i/images/1/image-1.jpg 1x" while the second image "/i/images/2/image-1 - Copy.jpg 1x", rendering the second image missing.

Chrome and possibly all other

AMP Version 1906191709480

merakmarey avatar Jun 28 '19 13:06 merakmarey

Do you have an example page where this happens?

sparhami avatar Jun 28 '19 21:06 sparhami

Try this, let me know if doesn't work, since its a dev server https://us.trapichero.com/a/wayne/pennsylvania/buy-or-sell/cells-and-accesories/safgasfgsfgsdgfs/1561593245-68.html

Thanks

Merak Marey Sr. Software Engineer. Miami. Florida. USA.LinkedIn : http://www.linkedin.com/in/merakmarey

El viernes, 28 de junio de 2019 05:11:14 p. m. EDT, Sepand Parhami <[email protected]> escribió:  

Do you have an example page where this happens?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

merakmarey avatar Jun 28 '19 22:06 merakmarey

Hmm, the problem seems to be the code doesn't play well with spaces in the filename currently. This works for src, but not srcset. We can fix this by simply using src if we never had a srcset to start with or uri-encoding any src we convert over to a srcset.

sparhami avatar Jun 28 '19 22:06 sparhami

I don't think that is the main issue. From my point of view the problem is this...why for the second srcset the "- Copy" is added, when the src uri is different from the first one?

merakmarey avatar Jun 28 '19 23:06 merakmarey

I'm not sure how you are generating the page, but the page source, as received from the server has:

        <amp-carousel layout="responsive" width="626" height="417" type="slides" autoplay controls loop delay="6000" id="slider-with-preview">
    
            <amp-img src="/i/images/1/gallery-1-1.jpg" width="626" height="417" layout="responsive" alt="aa" lightbox></amp-img>
    
            <amp-img src="/i/images/2/gallery-1-4-full - Copy.jpg" width="626" height="417" layout="responsive" alt="aa" lightbox></amp-img>
    
            <amp-img src="/i/images/3/gallery-1-4-full.jpg" width="626" height="417" layout="responsive" alt="aa" lightbox></amp-img>
    
            <amp-img src="/i/images/4/gallery-2-1.jpg" width="626" height="417" layout="responsive" alt="aa" lightbox></amp-img>
    
            <amp-img src="/i/images/5/gallery-2-1-full.jpg" width="626" height="417" layout="responsive" alt="aa" lightbox></amp-img>
    
</amp-carousel>

The src is then translated into a srcset, which fails to load due to the space. The adding of "- Copy" is prior to the AMP page being loaded, so you may want to look into how the page itself is generated.

As far as AMP itself is concerned, failing to load an image with a space in the name in the gallery seems to be the only issue.

sparhami avatar Jun 28 '19 23:06 sparhami

I see what you mean now, yes, the page is generating the " - Copy". So, only issue would be the treatment of the space in filling the srcset attribute.

merakmarey avatar Jun 29 '19 14:06 merakmarey

To recap: the problem is that if a src has spaces in it, we carry over the space when we generate a srcset from the src. This confuses the srcset parsing.

A simple change would be to call encodeURI when we convert a src attribute into a srcset, Another option would be to stop operating on amp-img, and instead do img.src on the internal <img>, which will give a URI encoded version.

Looking at the specs, it looks like spaces in URLs are not actually valid though, and may not work in all browsers. Since the original code is not valid, I don't think we should necessarily try to handle it.

Instead, we may want to add a validation rule to make sure src is a valid URL. A valid URL may have leading or trailing spaces, but may not include spaces inside, The rules from the spec make it a bit hard to piece together on what a valid URL is. A complete regex may not be ideal to implement, though there may be an existing library to check without us doing it as a regex. Alternatively, we may be able to simply check that a URI encoded version of all URLs are equivalent to the original URL.

@Gregable Any thoughts on validating this?

sparhami avatar Jul 08 '19 17:07 sparhami

encoding works ..

merakmarey avatar Jul 08 '19 17:07 merakmarey

Any new development on this?

merakmarey avatar Aug 31 '19 23:08 merakmarey

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 22 '21 02:02 stale[bot]

was this fixed? is AMP still a thing or is discontinued?

merakmarey avatar Feb 22 '21 13:02 merakmarey

I've demonstrated this working as expected in https://github.com/ampproject/amphtml/pull/32790. Closing.

If there is another example we can take a look at please re-open!

kristoferbaxter avatar Feb 22 '21 17:02 kristoferbaxter