Skip to content

Commit d4f348e

Browse files
committed
Normalize URI usage against space inside the URI string
1 parent 5d5d5e0 commit d4f348e

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

uri/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ All Notable changes to `League\Uri` will be documented in this file
2323
- `Uri` and `Http` normalization normalized IP against RFC3986 rules and not WHATWG rules.
2424
- `Uri::getOrigin` now follows WHATWG cross-origin definition
2525
- `Uri` host encoding compliance to RFC3986 is improved by supporting RFC3986 encoded URI properly
26+
- `Uri` parsing with strings started or ended with empty string are no longer allowed
27+
- `Uri` space are rawurlencoded.
2628

2729
### Deprecated
2830

uri/FactoryTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,6 @@ public static function invalidUriWithWhitespaceProvider(): iterable
566566
yield 'uri containing only whitespaces' => ['uri' => ' '];
567567
yield 'uri starting with whitespaces' => ['uri' => ' https://a/b?c'];
568568
yield 'uri ending with whitespaces' => ['uri' => 'https://a/b?c '];
569-
yield 'uri surrounded by whitespaces' => ['uri' => ' https://a/b?c '];
570-
yield 'uri containing whitespaces' => ['uri' => 'https://a/b ?c'];
571569
}
572570

573571
#[Test]

uri/HttpFactoryTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,5 @@ public static function invalidUriWithWhitespaceProvider(): iterable
4949
yield 'uri starting with whitespaces' => ['uri' => ' https://a/b?c'];
5050
yield 'uri ending with whitespaces' => ['uri' => 'https://a/b?c '];
5151
yield 'uri surrounded with whitespaces' => ['uri' => ' https://a/b?c '];
52-
yield 'uri containing whitespaces' => ['uri' => 'https://a/b ?c'];
5352
}
5453
}

uri/Uri.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,10 @@ public static function tryNew(Stringable|string|null $uri = ''): ?self
478478
*/
479479
public static function new(Stringable|string $uri = ''): self
480480
{
481-
return new self(...UriString::parse($uri));
481+
$uri = (string) $uri;
482+
trim($uri) === $uri || throw new SyntaxError(sprintf('The uri `%s` contains invalid characters', $uri));
483+
484+
return new self(...UriString::parse(str_replace(' ', '%20', $uri)));
482485
}
483486

484487
/**

0 commit comments

Comments
 (0)