asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
6.04k stars 555 forks source link

Is duckduckgo.com correct URL #356

Open dbadura opened 4 years ago

dbadura commented 4 years ago

is duckduckgo.com correct URL. I ask because there so no defined protocol and I think this is a bug.

elico commented 4 years ago

@dbadura Are you talking about IsURL? like in: https://play.golang.org/p/qk9EGc84HRl

Take a look at this answer which might be what you are looking for: https://github.com/asaskevich/govalidator/pull/40#issuecomment-72058206

In golang docs it states:

func Parse func Parse(rawurl string) (*URL, error) Parse parses rawurl into a URL structure.

The rawurl may be relative (a path, without a host) or absolute (starting with a scheme). Trying to parse a hostname and path without a scheme is invalid but may not necessarily return an error, due to parsing ambiguities.

So .. it's Invalid but for many applications even if there is no scheme prefix it's valid. These applications assume a default scheme like http:// or https:// or ftp:// etc.

I believe that this specific function should verify scheme.

https://github.com/asaskevich/govalidator/blob/master/validator.go#L104

What I have seen in the tests code that it's expected: https://github.com/asaskevich/govalidator/blob/master/validator_test.go#L697

sergeyglazyrindev commented 3 years ago

Hello guys! I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back Link to my repo: create issue there and we'll discuss it.