Skip to content

Commit

Permalink
Merge pull request #172 from thephpleague/bugfix/issue-171
Browse files Browse the repository at this point in the history
bug fix issue #171
  • Loading branch information
nyamsprod authored Aug 12, 2020
2 parents db14710 + e386a60 commit e3d51e7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ imporove `UriTemplate` implementation.

- `UriTemplate` complete rewrite by reducing deep nested array usage.
- Exception misleading message see issue [#167](https://github.com/thephpleague/uri/issues/167)
- `Uri::withScheme` Uri validation failed to catch the empty string as an invalid scheme.

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}
],
"require": {
"php": "^7.2",
"php": ">=7.2",
"ext-json": "*",
"psr/http-message": "^1.0",
"league/uri-interfaces": "^2.1"
Expand Down
6 changes: 3 additions & 3 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private function __construct(
*/
private function formatScheme(?string $scheme): ?string
{
if ('' === $scheme || null === $scheme) {
if (null === $scheme) {
return $scheme;
}

Expand All @@ -319,7 +319,7 @@ private function formatScheme(?string $scheme): ?string
return $formatted_scheme;
}

throw new SyntaxError(sprintf('The scheme `%s` is invalid', $scheme));
throw new SyntaxError(sprintf('The scheme `%s` is invalid.', $scheme));
}

/**
Expand Down Expand Up @@ -438,7 +438,7 @@ private function formatRegisteredName(string $host): string
$arr
);

if ($arr === []) {
if ([] === $arr) {
throw new SyntaxError(sprintf('Host `%s` is invalid', $host));
}

Expand Down
2 changes: 1 addition & 1 deletion src/UriString.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ private static function filterRegisteredName(string $host): string

$retval = idn_to_ascii($formatted_host, 0, INTL_IDNA_VARIANT_UTS46, $arr);

if ($arr === []) {
if ([] === $arr) {
throw new SyntaxError(sprintf('Host `%s` is not a valid IDN host', $host));
}

Expand Down
8 changes: 8 additions & 0 deletions tests/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,12 @@ public function testIssue167ExceptionReasonMisleadingMessage(): void

Uri::createFromString('file://example.org:80/home/jsmith/foo.txt');
}

public function testIssue171TheEmptySchemeShouldThrow(): void
{
self::expectException(SyntaxError::class);
self::expectExceptionMessage('The scheme `` is invalid.');

Uri::createFromString('domain.com')->withScheme('');
}
}

0 comments on commit e3d51e7

Please sign in to comment.