mikeerickson / validatorjs

A data validation library in JavaScript for the browser and Node.js, inspired by Laravel's Validator.
https://www.npmjs.com/package/validatorjs
MIT License
1.76k stars 280 forks source link

localhost url validation #284

Open zakashe opened 6 years ago

zakashe commented 6 years ago

I noticed that localhost is not valid according to URL validator.

examples url: http://localhost/ http://localhost/deeplink

this is the regex used for validation right now: /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i

the following change would fix it: /https?:\/\/(((www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{2,63})|(localhost))\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i I'd appreciate your feedback about it.

in addition, I'd like to know when is expected next release?

vict-shevchenko commented 6 years ago

Hi. I feel like http://localhost is not a valid url. You can check it by googling for URL RFC.

Also here is a good comment

My personal opinion is that the current behavior is correct and should not be changed. You may use http://127.0.0.1

zakashe commented 6 years ago

Hi @vict-shevchenko , thanks a lot for your comment.

according to the RFC file url is of the following pattern:

"file://" [ host | "localhost" ] "/" fpath

that obviously allows localhost as a the host, In addition, current implementation does not allow IDNs such as http://украина.icom.museum/.

obviously, IDNs also can be worked around with IP, or equivalent Latin version - from UX perspective I believe that both should be supported since both are legal URLs.

vict-shevchenko commented 6 years ago

Looks like you are right.

rosieks commented 5 years ago

Any chances to have it soon? I can create PR that fix it - there is correct Regex: https://github.com/jquery-validation/jquery-validation/blob/a9c20ec280ce3a968abbca5611dcd63f412b5d34/src/core.js#L1408

syabro commented 4 years ago

Any news?

mikeerickson commented 4 years ago

I will get an update posted during holiday break

syabro commented 3 years ago

@mikeerickson any update maybe? :)

mikeerickson commented 3 years ago

@syabro Hey there, my apologies. I thought this had already been fixed, but alas I missed it. I am working on a new build (version 3.23) which I will include this issue.

mikeerickson commented 3 years ago

Fixed in 3.23 release (pending tagging)

syabro commented 3 years ago

Thanks!

max-prtsr commented 1 year ago

@mikeerickson any news? :) 2023 :)