Skip to content

Commit

Permalink
Fix Uri::create() with empty scheme and string reference
Browse files Browse the repository at this point in the history
  • Loading branch information
ElGigi committed Mar 30, 2022
1 parent 942b474 commit 11e4107
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. This projec
to [Semantic Versioning] (http://semver.org/). For change log format,
use [Keep a Changelog] (http://keepachangelog.com/).

## [2.2.1] - 2022-03-30

### Fixed

- `Uri::create()` with empty scheme and string reference

## [2.2.0] - 2022-03-29

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function __construct(
public static function create(Uri|string $uri, Uri|string|null $ref = null): static
{
is_string($uri) && $uri = static::createFromString($uri);
is_string($ref) && $ref = static::createFromString($ref);

if (!empty($uri->getHost()) || null === $ref) {
if (empty($uri->getScheme())) {
Expand All @@ -66,7 +67,6 @@ public static function create(Uri|string $uri, Uri|string|null $ref = null): sta
return $uri;
}

is_string($ref) && $ref = static::createFromString($ref);
$userInfo = explode(':', $ref->getUserInfo(), 2);

return new static(
Expand Down
31 changes: 17 additions & 14 deletions tests/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,23 +257,26 @@ public function testCreateEmpty2()
public function testCreate_withoutSchema()
{
$uri = Uri::createFromString('//getberlioz.com:8080/doc');
$ref = Uri::createFromString('https://elgigi:[email protected]/doc/#qux');
$ref = Uri::createFromString($refUri = 'https://elgigi:[email protected]/doc/#qux');

$expected = [
'scheme' => 'https',
'host' => 'getberlioz.com',
'port' => 8080,
'path' => '/doc',
'query' => '',
'fragment' => '',
'userinfo' => '',
'authority' => 'getberlioz.com:8080'
];

$newUri = Uri::create($uri, $ref);

$this->testConstructAndGetters(
$newUri,
[
'scheme' => 'https',
'host' => 'getberlioz.com',
'port' => 8080,
'path' => '/doc',
'query' => '',
'fragment' => '',
'userinfo' => '',
'authority' => 'getberlioz.com:8080'
]
);
$this->testConstructAndGetters($newUri, $expected);

$newUri = Uri::create($uri, $refUri);

$this->testConstructAndGetters($newUri, $expected);
}

private function getUriToTest(): Uri
Expand Down

0 comments on commit 11e4107

Please sign in to comment.