Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't recognize a valid cloudinary url #63

Open
matiasfha opened this issue May 16, 2023 · 2 comments
Open

Can't recognize a valid cloudinary url #63

matiasfha opened this issue May 16, 2023 · 2 comments

Comments

@matiasfha
Copy link

Describe the bug
Using @unpic/svelte (but also happens with other unpic libs) there are some cloudinary URL that are not recognized and flagged as invalid

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://stackblitz.com/edit/vitejs-vite-qvjc1v?file=src/App.svelte
  2. Check the console output
  3. See error

Expected behavior
The image should be rendered
Find the image here

Screenshots

Screenshot 2023-05-15 at 21 12 07

Desktop (please complete the following information):

  • OS: macos
  • Browser Arc
  • Version Version 0.101.2 (38549)
  • Chromium Engine Version 112.0.5615.137
@ascorbic ascorbic transferred this issue from ascorbic/unpic-img May 16, 2023
@matiasfha
Copy link
Author

matiasfha commented May 17, 2023

Looking into cloudinary-util code this Regex written by Colby Fayock works

const REGEX_URL = /https?:\/\/(?<host>[^\/]+)\/(?<cloudName>[^\/]+)\/(?<assetType>image|images|video|videos|raw|files)\/(?<deliveryType>upload|fetch|private|authenticated|sprite|facebook|twitter|youtube|vimeo)?\/?(?<signature>s\-\-[a-zA-Z0-9]+\-\-)?\/?(?<transformations>(?:[^_\/]+_[^,\/]+,?\/?)*\/)*(?<version>v\d+|\w{1,2})\/(?<publicId>[^\s]+)$/;

the caveat with Colby's approach is it requires a version number - otherwise its almost impossible to confidently parse the url

@nicolas-besnard
Copy link

nicolas-besnard commented May 23, 2023

I have the same issue with an URL.

In the regex, the id capture group does not include the forward slashes in the URL, causing it to fail to match the provided URL. In my case, I have to modify the regex as follow /https?:\/\/(?<host>[^\/]+)\/(?<cloudName>[^\/]+)\/(?<assetType>image|video|raw)\/(?<deliveryType>upload|fetch|private|authenticated|sprite|facebook|twitter|youtube|vimeo)\/?(?<signature>s\-\-[a-zA-Z0-9]+\-\-)?\/?(?<transformations>(?:[^_\/]+_[^,\/]+,?)*)?\/(?:(?<version>v\d+)\/)?(?<id>[^\.^\s]+)\.?(?<format>[a-zA-Z]+$)?/g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants