[11.x] Handle spaces when validating a url #54550
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This closes #54546
Why
Str::isUrl
is used for Url Validation, ie$request->validate(['url' => 'required|url']);
If you're validating urls from a url param, such as :
http://local.test/example?url=https://laravel.com?query=taylor+otwell
orhttp://local.test/example?url=https://laravel.com?query=taylor%20otwell
the url you get back is decoded by PHP :
http://local.test/example?url=laravel.com?url=taylor otwell
this then fails the url validation, despite being technically a valid url before PHP decoded it.There are ways around it, but, it would be nice to use the request to validate it (in an ideal world).
What it adds
This PR adds a straight forward
str_replace
to handle spaces as felt the safest without touching the regex, the regex patterns already account for %20 too.Also added some basic tests to show no regression etc.
Feel free to close if not useful 👍🏻