adopted-ember-addons / ember-validators

A collection of EmberJS validators
Other
24 stars 40 forks source link

URL validation incorrectly require a period in the authority #59

Open bendemboski opened 6 years ago

bendemboski commented 6 years ago

In the URL regex:

/(?:([A-Za-z]+):)?(\/{0,3})[a-zA-Z0-9][a-zA-Z-0-9]*(\.[\w-]+)+([\w.,@?^=%&:\/~+#-{}]*[\w@?^=%&\/~+#-{}])??/

the (\.[\w-]+)+ is incorrect as it requires at least one dot in the authority, which is not a requirement of valid URLs, and prevents, for example, using http://localhost which is a valid URL. I think maybe changing the \. to a \.? would fix it, but rather than hacking on the existing regex, it probably makes sense to go and find a regex or library that validates URLs and doesn't exhibit this bug.