You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For some reason it seems that calling /link?url=https://www.foo.com/?utm_campaign=some%20campaign in my application will fail to validate the url parameter there. Calling Str::isUrl('https://www.foo.com/?utm_campaign=some%20campaign')` directly in tinker returns true though. However, dumping $request->input('url') in the controller reveals that the %20 character there has done MIA. That also happens if I use + as a space encoder.
Is this supposed to fail like this? My understanding is that https://www.foo.com/?utm_campaign=some%20campaign is a completely valid URL though (and directly calling Str::isUrl('https://www.foo.com/?utm_campaign=some%20campaign') confirms that). Or should spaces in query parameters always be double encoded when passing them to Laravel for validation?
One workaround/hack is to add these lines before the validation is done:
I think this is down to PHP decoding it, and then when it's validating the space is included, which then makes it invalid.. It does seem odd. Maybe a custom validator is a better way around it.. or maybe it'd be better to post it rather than a url param, that way it doesn't get decoded. Not sure if it belongs in the framework as it's an edgecase I guess, I did open a PR but closed it after some thought.
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
Laravel Version
11.41.3
PHP Version
8.4.3
Database Driver & Version
No response
Description
For some reason it seems that calling
/link?url=https://www.foo.com/?utm_campaign=some%20campaign
in my application will fail to validate theurl
parameter there. CallingStr::isUrl('
https://www.foo.com/?utm_campaign=some%20campaign')` directly in tinker returnstrue
though. However, dumping$request->input('url')
in the controller reveals that the%20
character there has done MIA. That also happens if I use+
as a space encoder.Steps To Reproduce
routes/web.php
:tests/Feature/UrlValidatorTest.php
:Test 2 and 4 will then fail here.
Is this supposed to fail like this? My understanding is that
https://www.foo.com/?utm_campaign=some%20campaign
is a completely valid URL though (and directly callingStr::isUrl('https://www.foo.com/?utm_campaign=some%20campaign')
confirms that). Or should spaces in query parameters always be double encoded when passing them to Laravel for validation?One workaround/hack is to add these lines before the validation is done:
Reproduction repo: https://github.com/carestad/laravel-url-validation-bug
The text was updated successfully, but these errors were encountered: