[5.4] Optimize UrlGenerator->isValidUrl()#18566
Conversation
| public function isValidUrl($path) | ||
| { | ||
| if (! Str::startsWith($path, ['#', '//', 'mailto:', 'tel:', 'http://', 'https://'])) { | ||
| if (! preg_match('~^(#|//|https?://|mailto:|tel:)~', $path)) { |
There was a problem hiding this comment.
it should include http as well?
There was a problem hiding this comment.
It does, https?:// matches https:// and http://
|
I investigated why the http[s] protocols had been added (ec1b1ae) while the So, I guess it's to allow internationalized domain names, which are not supported by filter_var('http://스타벅스코리아.com', FILTER_VALIDATE_URL) // false |
|
It should work with Anyway shouldn't we consider making this check more strict? Currently it seems that |
|
It should be fine as it is. This method is not really for proper validation, but just to determine if the argument is a route or an URL, so that the developer can pass both to e.g. |
UrlGenerator->to()andUrlGenerator->asset()are quite slow. Investigating about this, I found outUrlGenerator->validUrl()was a bottleneck, taking by itself about half of the total execution time.Then, I found out this method could be made significantly faster:
Before: 673 ms
After: 76 ms