CodeIgniter4: valid_url does not work correctly
Hello!
Url validation doesn’t work, if I pass a string like this asdf
it passes the validation which should be wrong
my validation is as follows:
'rules' => 'permit_empty|valid_url|max_length[512]'
Hugs!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (14 by maintainers)
Commits related to this issue
- feat: add valid_url_strict rule Fixes #3156 — committed to kenjis/CodeIgniter4 by kenjis 3 years ago
- feat: add valid_url_strict rule Fixes #3156 — committed to kenjis/CodeIgniter4 by kenjis 3 years ago
I’m reopening this issue because I think there are some things that need to be addressed.
RFC 2396
is obsolete. The new doc is RFC 3986Here’s my opinion:
a) We need
valid_url_strict
or something that has a lower tolerance for actual URLs. b) I think the current validator should not pass simple strings like “asdf”, but in order to prevent a breaking change we should still accept “CodeIgniter.com”. Probably could check for a scheme and pass to a) if found, use a simple regex otherwise.Just to note, Laravel and Symfony use a super convoluted regex to check validity (https://github.com/laravel/framework/blob/cb398188729f51e63d6fd0dc1ed9009fcf76b404/src/Illuminate/Validation/Concerns/ValidatesAttributes.php#L1732).
In my opinion.
valid_url
should only allow URL to pass inspection. Suchasdf
,localhost
,codeigniter.com
string, it not a URL. It 's domain.I think I would only mention that if the protocol part in the address is omitted it will be added automatically before doing a check. This is just more accurate and nobody will have doubts about how things are working.
About
URI::validate()
- it’s a good idea. If I remember it correctly we’re usingparse_url()
in URI class.I wonder how many false-positive results we can get.
Not a bug, sorry -
asdf
is a valid hostname.Please take a look at RFC 2396 - these are the rules behind
FILTER_VALIDATE_URL
.But we’re open to adding a new rule that will be more “restrictive”.