Skip to content

Commit

Permalink
Merge pull request #47 from Bontah/avoid_null_from_uri_getPath
Browse files Browse the repository at this point in the history
Avoid `null` return value from `Uri#getPath()` leading to a crash in `UriNormalize`
  • Loading branch information
Ocramius authored Feb 7, 2022
2 parents 79e8baa + 9c0b3dd commit 3da1df5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/UriNormalize.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public function filter($value)
*/
protected function enforceScheme(Uri $uri)
{
$path = $uri->getPath();
$path = $uri->getPath() ?? '';

if (strpos($path, '/') !== false) {
[$host, $path] = explode('/', $path, 2);
$path = '/' . $path;
Expand Down
1 change: 1 addition & 0 deletions test/UriNormalizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static function enforcedSchemeTestcaseProvider()
['http', 'www.example.com/foo/bar?q=q', 'http://www.example.com/foo/bar?q=q'],
['ftp', 'www.example.com/path/to/file.ext', 'ftp://www.example.com/path/to/file.ext'],
['http', '/just/a/path', '/just/a/path'], // cannot be enforced, no host
['http', '', ''],
];
}

Expand Down

0 comments on commit 3da1df5

Please sign in to comment.