cloudinary-api icon indicating copy to clipboard operation
cloudinary-api copied to clipboard

Fix truncating urls for paths with multiple dots (#46)

Open gpoole opened this issue 2 years ago • 9 comments

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

gpoole avatar Nov 28 '22 05:11 gpoole

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.

gpoole avatar Nov 28 '22 05:11 gpoole

Nice solution @gpoole What do you think about this one though?

orimdominic avatar Jan 17 '23 01:01 orimdominic

@colbyfayock can you take a look on this?

mayashavin avatar Feb 14 '23 14:02 mayashavin

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.

gpoole avatar Feb 15 '23 04:02 gpoole

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

orimdominic avatar Feb 15 '23 04:02 orimdominic

im not great at regex, but one thing to consider is the extension isn't required

  • .../myimage.png
  • .../myimage

colbyfayock avatar Feb 21 '23 17:02 colbyfayock

@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.

gpoole avatar Feb 21 '23 21:02 gpoole

@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.

This is great! :+1:

orimdominic avatar Feb 22 '23 06:02 orimdominic