vue-lazyload icon indicating copy to clipboard operation
vue-lazyload copied to clipboard

Using data-src fails on urls containing commas

Open jorngeorg opened this issue 5 years ago • 6 comments

If you have a srcset looking something like this:

https://some.domain.co/animage.jpg?rect=0,4,1936,1084&w=500&h=280&q=80&fit=crop&auto=format 500w, 
https://some.domain.co/animage.jpg?rect=0,3,1936,1086&w=1000&h=561&q=80&fit=crop&auto=format 1000w, 
https://some.domain.co/animage.jpg?rect=0,3,1936,1087&w=2000&h=1123&q=80&fit=crop&auto=format 2000w

loading will fail because it return a src image like this

1087&w=2000&h=1123&q=80&fit=crop&auto=format

jorngeorg avatar Jul 05 '19 15:07 jorngeorg

After some digging, I found the culprit to be this line https://github.com/hilongjw/vue-lazyload/blob/master/src/util.js#L74

options = options.trim().split(',')

The split expression here needs to be bit more clever, taking into account that an url can contain a comma.

jorngeorg avatar Jul 06 '19 11:07 jorngeorg

OMG, in deed is quite a problem. If you are using Cloudinary for example, the transformations in the path uses commas like this https://res.cloudinary.com/alvarosaburido/image/upload/c_scale,q_auto,w_320/v1563876252/alvaro-saburido-portfolio.png

I will create a PR for this.

alvarosabu avatar Aug 01 '19 18:08 alvarosabu

Any update on this issue? Unable to use this plugin with Cloudinary at this time.

reganjohnson avatar Aug 22 '19 13:08 reganjohnson

My PR still open tho. No news about it

alvarosabu avatar Oct 17 '19 12:10 alvarosabu

for a temporary solution to this is to encode the comma.

string.replace(/,/g, "%2C")

blek-id avatar Jan 17 '20 11:01 blek-id

+1 I also had issues with sanity urls. They have commas when they are cropped

vin-ni avatar Nov 29 '21 15:11 vin-ni