Skip to content

Commit de49377

Browse files
committed
Adding missing tests
1 parent 58ccecf commit de49377

3 files changed

Lines changed: 27 additions & 21 deletions

File tree

Contracts/UriRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function toNormalizedString(): ?string;
4545
*
4646
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-6.2
4747
*/
48-
public function toDisplayString(): ?string;
48+
public function toDisplayString(): string;
4949

5050
/**
5151
* Returns the string representation as a URI reference.

UriString.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,40 +338,45 @@ public static function normalizeAuthority(Stringable|string $authority): string
338338
*/
339339
public static function resolve(Stringable|string $uri, Stringable|string|null $baseUri = null): string
340340
{
341+
$uri = (string) $uri;
341342
if ('' === $uri) {
342343
$uri = $baseUri ?? throw new SyntaxError('The uri can not be the empty string when there\'s no base URI.');
343344
}
344345

345-
$uri = self::parse($uri);
346-
$baseUri = null !== $baseUri ? self::parse($baseUri) : $uri;
347-
if (null === $baseUri['scheme']) {
346+
$uriComponents = self::parse($uri);
347+
$baseUriComponents = $uriComponents;
348+
if (null !== $baseUri && (string) $uri !== (string) $baseUri) {
349+
$baseUriComponents = self::parse($baseUri);
350+
}
351+
352+
if (null === $baseUriComponents['scheme']) {
348353
throw new SyntaxError('The base URI must be an absolute URI or null; If the base URI is null the URI must be an absolute URI.');
349354
}
350355

351-
if (null !== $uri['scheme'] && '' !== $uri['scheme']) {
352-
$uri['path'] = self::removeDotSegments($uri['path']);
356+
if (null !== $uriComponents['scheme'] && '' !== $uriComponents['scheme']) {
357+
$uriComponents['path'] = self::removeDotSegments($uriComponents['path']);
353358

354-
return UriString::build($uri);
359+
return UriString::build($uriComponents);
355360
}
356361

357-
if (null !== self::buildAuthority($uri)) {
358-
$uri['scheme'] = $baseUri['scheme'];
359-
$uri['path'] = self::removeDotSegments($uri['path']);
362+
if (null !== self::buildAuthority($uriComponents)) {
363+
$uriComponents['scheme'] = $baseUriComponents['scheme'];
364+
$uriComponents['path'] = self::removeDotSegments($uriComponents['path']);
360365

361-
return UriString::build($uri);
366+
return UriString::build($uriComponents);
362367
}
363368

364-
[$path, $query] = self::resolvePathAndQuery($uri, $baseUri);
369+
[$path, $query] = self::resolvePathAndQuery($uriComponents, $baseUriComponents);
365370
$path = UriString::removeDotSegments($path);
366-
if ('' !== $path && '/' !== $path[0] && null !== self::buildAuthority($baseUri)) {
371+
if ('' !== $path && '/' !== $path[0] && null !== self::buildAuthority($baseUriComponents)) {
367372
$path = '/'.$path;
368373
}
369374

370-
$baseUri['path'] = $path;
371-
$baseUri['query'] = $query;
372-
$baseUri['fragment'] = $uri['fragment'];
375+
$baseUriComponents['path'] = $path;
376+
$baseUriComponents['query'] = $query;
377+
$baseUriComponents['fragment'] = $uriComponents['fragment'];
373378

374-
return UriString::build($baseUri);
379+
return UriString::build($baseUriComponents);
375380
}
376381

377382
/**

UriStringTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,11 @@ public function it_fails_parsing_uri_string_with_whitespace(string $uri): void
10251025

10261026
public static function invalidUriWithWhitespaceProvider(): iterable
10271027
{
1028+
yield 'empty string' => ['uri' => ''];
10281029
yield 'uri containing only whitespaces' => ['uri' => ' '];
1029-
yield 'uri stating with whitespace' => ['uri' => ' https://a/b?c'];
1030-
yield 'uri ending with whitespace' => ['uri' => 'https://a/b?c '];
1031-
yield 'uri surrounded with whitespace' => ['uri' => ' https://a/b?c '];
1032-
yield 'uri containing with whitespace' => ['uri' => 'https://a/b ?c'];
1030+
yield 'uri starting with whitespaces' => ['uri' => ' https://a/b?c'];
1031+
yield 'uri ending with whitespaces' => ['uri' => 'https://a/b?c '];
1032+
yield 'uri surrounded by whitespaces' => ['uri' => ' https://a/b?c '];
1033+
yield 'uri containing with whitespaces' => ['uri' => 'https://a/b ?c'];
10331034
}
10341035
}

0 commit comments

Comments
 (0)