Skip to content

Commit

Permalink
Revert SensitiveParameter improved usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Sep 20, 2024
1 parent 861c2a7 commit eb091b8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
3 changes: 1 addition & 2 deletions BaseUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
{
Expand Down
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 5 additions & 5 deletions Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}

Expand Down
20 changes: 8 additions & 12 deletions Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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']];
}

Expand Down Expand Up @@ -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
);
}
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit eb091b8

Please sign in to comment.