Skip to content

Commit 0d8169e

Browse files
committed
Ensure scheme returns null rather than an empty string.
Fixes #53.
1 parent ee17687 commit 0d8169e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Pdp/Uri/Url.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ public function __construct(
8080
$query,
8181
$fragment
8282
) {
83-
$this->scheme = mb_strtolower($scheme, 'UTF-8');
83+
// Ensure scheme is either a legit scheme or null, never an empty string.
84+
// @see https://github.com/jeremykendall/php-domain-parser/issues/53
85+
$this->scheme = mb_strtolower($scheme, 'UTF-8') ?: null;
8486
$this->user = $user;
8587
$this->pass = $pass;
8688
$this->host = $host;

tests/src/Pdp/Uri/UrlTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,18 @@ public function testSchemeAlwaysConvertedToLowerCasePerRFC3986()
181181
$url = $this->parser->parseUrl($spec);
182182
$this->assertEquals($expected, $url->__toString());
183183
}
184+
185+
/**
186+
* Scheme should return null when scheme is not provided.
187+
*
188+
* @group issue53
189+
*
190+
* @see https://github.com/jeremykendall/php-domain-parser/issues/53
191+
*/
192+
public function testSchemeReturnsNullIfNotProvidedToParser()
193+
{
194+
$spec = 'google.com';
195+
$url = $this->parser->parseUrl($spec);
196+
$this->assertNull($url->getScheme());
197+
}
184198
}

0 commit comments

Comments
 (0)