Skip to content

Commit 0a0c8b2

Browse files
committed
Fix php8.2 deprecation: preg_match():
- Passing null to parameter laravel#2 ($subject) of type string is deprecated
1 parent fc2992e commit 0a0c8b2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Illuminate/Routing/UrlGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,10 @@ public function format($root, $path, $route = null)
674674
*/
675675
public function isValidUrl($path)
676676
{
677+
if ($path === null) {
678+
return false;
679+
}
680+
677681
if (! preg_match('~^(#|//|https?://|(mailto|tel|sms):)~', $path)) {
678682
return filter_var($path, FILTER_VALIDATE_URL) !== false;
679683
}

tests/Routing/RoutingUrlGeneratorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,17 @@ public function testUrlGenerationWithOptionalParameters(): void
20012001
$url->route('tenantPostUserOptionalMethod', ['concreteTenant', 'concretePost', 'concreteUser', 'concreteMethod']),
20022002
);
20032003
}
2004+
2005+
public function testIsValidUrlPathIsNull()
2006+
{
2007+
$url = new UrlGenerator(
2008+
$routes = new RouteCollection,
2009+
Request::create('https://www.foo.com/')
2010+
);
2011+
2012+
$this->assertSame(false, $url->isValidUrl(null));
2013+
}
2014+
20042015
}
20052016

20062017
class RoutableInterfaceStub implements UrlRoutable

0 commit comments

Comments
 (0)