From eb091b8f0b7660ff6e0c6bc2aa2c6aa085bb6bee Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Fri, 20 Sep 2024 05:50:58 +0200 Subject: [PATCH] Revert SensitiveParameter improved usage --- BaseUri.php | 3 +-- CHANGELOG.md | 1 - Http.php | 10 +++++----- Uri.php | 20 ++++++++------------ 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/BaseUri.php b/BaseUri.php index 99b5c630d..c29dc2799 100644 --- a/BaseUri.php +++ b/BaseUri.php @@ -53,7 +53,6 @@ class BaseUri implements Stringable, JsonSerializable, UriAccess protected readonly ?string $nullValue; /** - * @param Psr7UriInterface|UriInterface $uri * @param UriFactoryInterface|null $uriFactory Deprecated, will be removed in the next major release */ final protected function __construct( @@ -271,7 +270,7 @@ public function hasIdn(): bool } /** - * Tells whether the URI contains an IPv4 regardless if it is mapped or native + * Tells whether the URI contains an IPv4 regardless if it is mapped or native. */ public function hasIPv4(): bool { diff --git a/CHANGELOG.md b/CHANGELOG.md index 529408944..a36f43639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,6 @@ All Notable changes to `League\Uri` will be documented in this file ### Fixed -- Adding `SensitiveParameter` attribute in the `Uri` and the `BaseUri` class. - Improve PSR-7 `Http` class implementation. - `BaseUri::from` will compress the IPv6 host to its compressed form if possible. diff --git a/Http.php b/Http.php index d2fce116b..51c23c797 100644 --- a/Http.php +++ b/Http.php @@ -43,7 +43,7 @@ private function __construct(UriInterface $uri) } /** - * PSR-7 UriInterface makes the following normalization + * PSR-7 UriInterface makes the following normalization. * * Safely stringify input when possible for League UriInterface compatibility. * @@ -92,19 +92,19 @@ public static function fromComponents(array $components): self 'port' => null, 'path' => '', 'query' => null, 'fragment' => null, ]; - if ($components['user'] === '') { + if ('' === $components['user']) { $components['user'] = null; } - if ($components['pass'] === '') { + if ('' === $components['pass']) { $components['pass'] = null; } - if ($components['query'] === '') { + if ('' === $components['query']) { $components['query'] = null; } - if ($components['fragment'] === '') { + if ('' === $components['fragment']) { $components['fragment'] = null; } diff --git a/Uri.php b/Uri.php index d5509a4c9..44737ab44 100644 --- a/Uri.php +++ b/Uri.php @@ -380,7 +380,7 @@ private function formatPort(?int $port = null): ?int /** * Create a new instance from a string. */ - public static function new(#[SensitiveParameter] Stringable|string $uri = ''): self + public static function new(Stringable|string $uri = ''): self { $components = match (true) { $uri instanceof UriInterface => $uri->toComponents(), @@ -405,8 +405,8 @@ public static function new(#[SensitiveParameter] Stringable|string $uri = ''): s * The returned URI must be absolute. */ public static function fromBaseUri( - #[SensitiveParameter] Stringable|string $uri, - #[SensitiveParameter] Stringable|string|null $baseUri = null + Stringable|string $uri, + Stringable|string|null $baseUri = null ): self { $uri = self::new($uri); $baseUri = BaseUri::from($baseUri ?? $uri); @@ -441,7 +441,7 @@ public static function fromTemplate(UriTemplate|Stringable|string $template, ite * * @param InputComponentMap $components a hash representation of the URI similar to PHP parse_url function result */ - public static function fromComponents(#[SensitiveParameter] array $components = []): self + public static function fromComponents(array $components = []): self { $components += [ 'scheme' => null, 'user' => null, 'pass' => null, 'host' => null, @@ -603,7 +603,7 @@ public static function fromRfc8089(Stringable|string $uri): UriInterface /** * Create a new instance from the environment. */ - public static function fromServer(#[SensitiveParameter] array $server): self + public static function fromServer(array $server): self { $components = ['scheme' => self::fetchScheme($server)]; [$components['user'], $components['pass']] = self::fetchUserInfo($server); @@ -631,7 +631,7 @@ private static function fetchScheme(array $server): string * * @return non-empty-array{0: ?string, 1: ?string} */ - private static function fetchUserInfo(#[SensitiveParameter] array $server): array + private static function fetchUserInfo(array $server): array { $server += ['PHP_AUTH_USER' => null, 'PHP_AUTH_PW' => null, 'HTTP_AUTHORIZATION' => '']; $user = $server['PHP_AUTH_USER']; @@ -675,10 +675,6 @@ private static function fetchHostname(array $server): array $matches['port'] = (int) $matches['port']; } - if (null !== $matches['host']) { - $matches['host'] = (string) $matches['host']; - } - return [$matches['host'], $matches['port'] ?? $server['SERVER_PORT']]; } @@ -812,7 +808,7 @@ private function formatFilePath(string $path): string { return (string) preg_replace_callback( self::REGEXP_FILE_PATH, - static fn (array $matches): string => $matches['delim'].$matches['volume'].':'.$matches['rest'], + static fn (array $matches): string => $matches['delim'].$matches['volume'].(isset($matches['rest']) ? ':'.$matches['rest'] : ''), $path ); } @@ -1054,7 +1050,7 @@ public function withScheme(Stringable|string|null $scheme): UriInterface * * @throws SyntaxError if the submitted data cannot be converted to string */ - private function filterString(#[SensitiveParameter] Stringable|string|null $str): ?string + private function filterString(Stringable|string|null $str): ?string { $str = match (true) { $str instanceof UriComponentInterface => $str->value(),