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

isURL function is not working as expected in some cases #2

Open
carlos-ds opened this issue May 14, 2020 · 6 comments
Open

isURL function is not working as expected in some cases #2

carlos-ds opened this issue May 14, 2020 · 6 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@carlos-ds
Copy link

carlos-ds commented May 14, 2020

Hi,

First of all, I want to congratulate the author because I believe this is a very promising project. And you've obviously put a lot of time into this. If there is any way I can help, please let me know.

Now, to the point: I've been looking into the code and I've found that the isURL function is not always working as expected. For example, the following code returns true:

const DW = require("deep-waters");
console.log(DW.isURL("www.google"));

As you mentioned in the comments of isURL.js, the code for this function is derived from this Stackoverflow question. The example I've used above was also already mentioned in the comments on Stackoverflow as an invalid example.

Now, the question "what is a valid URL?" is indeed quire ambiguous. But to me, "www.google" should return false for this function. In any case, it would be best to either include specific documentation/examples to explain what works and what not. Were you thinking about also adding more documentation to this project?

As a second measure, we can try to improve the regular expression so that it returns false for these type of cases.

What do you think?

@antonioru antonioru added bug Something isn't working enhancement New feature or request labels May 14, 2020
@antonioru
Copy link
Owner

Hello @carlos-ds
thank you very much.
I am flatted of your attention and yes I shall put everything that needs to keep this project as promising as it looks like.

Regarding the bug: I think you're right, I've been a little too shallow in writing that validator and I apologise I haven't noticed stack overflow already mentioned it wasn't a good regex to use.

I would be glad if you want to contribute by changing that validator and its tests.

At the moment I am working on a quite-big refectory of the library in order to allow validators to return a proper customisable and composable error message so I can't promise I will be able to fix this validator soon, I apologise.

Please let me know if you'll fix the this validator tho :)

cheers

@antonioru
Copy link
Owner

Oh btw... yes I will improve the documentation as soon as I finish the refactory

@carlos-ds
Copy link
Author

Alright, but then perhaps it's best I have a go at that isURL function after you've done the necessary refactoring. When you come with more details on that refactoring, I might be able to help.

@GregoryLebret-STW
Copy link

@antonioru Great job on this library. I noticed isURL fails if there is a colon in the url, which is valid.

It's probably better to completely refactor this function instead of patching with PRs.

Thanks again for the hard work.

@antonioru
Copy link
Owner

antonioru commented Jun 18, 2020

@GregoryLebret-STW thanks for pointing this out

I'm currently working on a huge refactory that shall allow validators to return error messages and developers to compose their own error messages.

@carlos-ds pointed out that the isURL validator already has some bugs so I took the opportunity to completely rewrite it by using (@dperini) Diego Perini's regex which is one of the most accurate I've found so far, you can find the new isURL version along with the refactory here:

https://github.com/antonioru/deep-waters/blob/feature/with-error/src/isURL.js

This will be part of the release 1.0.0 which is due as soon as possible...

@antonioru
Copy link
Owner

Some interesting (I hope) new features I'm introducing with the refactory:

  • the pre existing validators are all memoized functions
  • createValidator utility to create new memoized validators
  • switchCase function to compose with conditions
  • ResponseMonad to create your own composing function
  • withError to override the standard error messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants