cloudinary-api
                                
                                
                                
                                    cloudinary-api copied to clipboard
                            
                            
                            
                        Fix truncating urls for paths with multiple dots (#46)
Fix for public IDs containing multiple dots before the extension getting truncated. For example, in 0.2.4  https://res.cloudinary.com/xyz/image/upload/v111111111/Folder/Name.With.Multiple.Dots.png is extracted as Folder/Name instead of Folder/Name.With.Multiple.Dots. This fix (maybe incorrectly) assumes everything after the last . is an extension, but it does correctly include any dots before the last . in the ID so it should work for most cases.
Not sure if it should be more careful about specifically only removing image and video extensions but I thought that might be over-complicating it.
Fixes #46
Sorry for messing around with the related issue, I thought it was related to #22 but I think actually it's a slightly different problem after re-reading the original description closely.
Nice solution @gpoole What do you think about this one though?
@colbyfayock can you take a look on this?
Sorry, I missed that @orimdominic. That seems reasonable and probably more foolproof, although I think the path.extname part won't work in browsers. The big regex could be replaced with that split though which seems a lot simpler. I'll take a look if I get time.
Nice to know @gpoole I was working with Node.js when I developed that solution. I had no idea this library would be used in the browser too
im not great at regex, but one thing to consider is the extension isn't required
- .../myimage.png
 - .../myimage
 
@colbyfayock as the extension is removed with a .replace, it will only remove one if found but if there is no extension nothing will happen. I've added a test validating that's the case.
@orimdominic I had a go at the solution you suggested but unfortunately it doesn't quite work, since the extracted ID with that method includes the v12345/ part of the path, which caused tests to fail. I was going to try stripping the v12345 bit, but when I was looking at the existing regex again I noticed that it also handles a lot of variants of the URL format, such as the path including private/ or youtube/ instead of upload/, so I think it's probably safer and simpler to keep it as is.
@colbyfayock as the extension is removed with a
.replace, it will only remove one if found but if there is no extension nothing will happen. I've added a test validating that's the case.@orimdominic I had a go at the solution you suggested but unfortunately it doesn't quite work, since the extracted ID with that method includes the
v12345/part of the path, which caused tests to fail. I was going to try stripping thev12345bit, but when I was looking at the existing regex again I noticed that it also handles a lot of variants of the URL format, such as the path includingprivate/oryoutube/instead ofupload/, so I think it's probably safer and simpler to keep it as is.
This is great! :+1: