@@ -264,24 +264,32 @@ class CloudinaryFile {
264264 const prefix = getUrlPrefix ( this . cloudName , this . urlConfig ) ;
265265 const transformationString = transformation ? transformation . toString ( ) : '' ;
266266 const version = getUrlVersion ( this . publicID , this . version , this . urlConfig . forceVersion ) ;
267+ const publicID = this . publicID ;
267268
268- const publicID = this . publicID
269- // Serialize the publicID, but leave slashes alone.
270- // we can't use serializeCloudinaryCharacters because that does both things (, and /)
271- . replace ( / , / g, '%2C' ) ;
269+ if ( typeof transformation === 'string' ) {
272270
273- // Resource type is a mixture of assetType, deliveryType and various URL Configurations
274- // Note how `suffix` changes both image/upload (resourceType) and also is appended at the end
275- const url = [ prefix , this . getResourceType ( ) , this . getSignature ( ) , transformationString , version , publicID , this . suffix ]
276- . filter ( ( a ) => a )
277- . join ( '/' ) ;
271+ const url = [ prefix , this . getResourceType ( ) , this . getSignature ( ) , transformationString , version , publicID . replace ( / , / g, '%2C' ) , this . suffix ]
272+ . filter ( ( a ) => a )
273+ . join ( '/' ) ;
278274
279- if ( typeof transformation === 'string' ) {
280275 return url ;
281276 } else {
282- const safeURL = encodeURI ( url )
283- . replace ( / \? / g, '%3F' )
284- . replace ( / = / g, '%3D' ) ;
277+ // Avoid applying encodeURI on entire string in case where we have transformations with comma (i.e. f_auto,q_auto)
278+ // Since encodeURI does not encode commas we replace commas *only* on the publicID
279+ const safeURL =
280+ [
281+ encodeURI ( prefix ) ,
282+ this . getResourceType ( ) ,
283+ this . getSignature ( ) ,
284+ encodeURI ( transformationString ) ,
285+ version ,
286+ encodeURI ( publicID ) . replace ( / , / g, '%2C' ) ,
287+ this . suffix && encodeURI ( this . suffix )
288+ ]
289+ . filter ( ( a ) => a )
290+ . join ( '/' )
291+ . replace ( / \? / g, '%3F' )
292+ . replace ( / = / g, '%3D' ) ;
285293
286294 const queryParams = new URLSearchParams ( this . urlConfig . queryParams as Record < string , string > ) ;
287295
0 commit comments