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 2efefeb commit b0f4ec5
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 76 deletions.
1 change: 0 additions & 1 deletion components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ All Notable changes to `League\Uri\Components` will be documented in this file

### Fixed

- Adding `SensitiveParameter` attribute in the `UserInfo` and the `Authority` class.
- Remove Usage of PSR-7 `UriInterface` in `UrlSearchParams` class
- Normalizes `fromUri` to return the same value for the component if the URI object has the same string representation.

Expand Down
14 changes: 7 additions & 7 deletions components/Components/Authority.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(
/**
* @throws SyntaxError If the component contains invalid HostInterface part.
*/
public static function new(#[SensitiveParameter] Stringable|string|null $value = null): self
public static function new(Stringable|string|null $value = null): self
{
$components = UriString::parseAuthority(self::filterComponent($value));

Expand All @@ -64,7 +64,7 @@ public static function new(#[SensitiveParameter] Stringable|string|null $value =
/**
* Create a new instance from a URI object.
*/
public static function fromUri(#[SensitiveParameter] Stringable|string $uri): self
public static function fromUri(Stringable|string $uri): self
{
$uri = self::filterUri($uri);

Expand All @@ -87,7 +87,7 @@ public static function fromUri(#[SensitiveParameter] Stringable|string $uri): se
* port? : ?int
* } $components
*/
public static function fromComponents(#[SensitiveParameter] array $components): self
public static function fromComponents(array $components): self
{
$components += ['user' => null, 'pass' => null, 'host' => null, 'port' => null];

Expand All @@ -104,7 +104,7 @@ public function value(): ?string
}

private static function getAuthorityValue(
#[SensitiveParameter] UserInfoInterface $userInfo,
UserInfoInterface $userInfo,
HostInterface $host,
PortInterface $port
): ?string {
Expand Down Expand Up @@ -200,7 +200,7 @@ public function withUserInfo(Stringable|string|null $user, #[SensitiveParameter]
*
* Create a new instance from a URI object.
*/
public static function createFromUri(#[SensitiveParameter] UriInterface|Psr7UriInterface $uri): self
public static function createFromUri(UriInterface|Psr7UriInterface $uri): self
{
return self::fromUri($uri);
}
Expand All @@ -215,7 +215,7 @@ public static function createFromUri(#[SensitiveParameter] UriInterface|Psr7UriI
*
* Returns a new instance from a string or a stringable object.
*/
public static function createFromString(#[SensitiveParameter] Stringable|string $authority): self
public static function createFromString(Stringable|string $authority): self
{
return self::new($authority);
}
Expand Down Expand Up @@ -255,7 +255,7 @@ public static function createFromNull(): self
* port? : ?int
* } $components
*/
public static function createFromComponents(#[SensitiveParameter] array $components): self
public static function createFromComponents(array $components): self
{
return self::fromComponents($components);
}
Expand Down
1 change: 0 additions & 1 deletion components/Components/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use League\Uri\Idna\Converter as IdnConverter;
use League\Uri\IPv4\Converter as IPv4Converter;
use League\Uri\IPv4Normalizer;
use League\Uri\IPv6\Converter;
use League\Uri\Uri;
use Psr\Http\Message\UriInterface as Psr7UriInterface;
use Stringable;
Expand Down
3 changes: 2 additions & 1 deletion components/Components/SchemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace League\Uri\Components;

use Generator;
use League\Uri\Contracts\UriInterface;
use League\Uri\Exceptions\SyntaxError;
use League\Uri\Http;
Expand Down Expand Up @@ -125,7 +126,7 @@ public function it_can_detect_information_about_special_schemes(
self::assertSame($defaultPort, $schemeObject->defaultPort());
}

public static function getSchemeInfoProvider(): \Generator
public static function getSchemeInfoProvider(): Generator
{
yield 'detect an HTTP URL' => [
'scheme' => 'http',
Expand Down
14 changes: 7 additions & 7 deletions components/Components/UserInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(
/**
* Create a new instance from a URI object.
*/
public static function fromUri(#[SensitiveParameter] Stringable|string $uri): self
public static function fromUri(Stringable|string $uri): self
{
$uri = self::filterUri($uri);

Expand All @@ -64,7 +64,7 @@ public static function fromUri(#[SensitiveParameter] Stringable|string $uri): se
/**
* Create a new instance from an Authority object.
*/
public static function fromAuthority(#[SensitiveParameter] Stringable|string|null $authority): self
public static function fromAuthority(Stringable|string|null $authority): self
{
return match (true) {
$authority instanceof AuthorityInterface => self::new($authority->getUserInfo()),
Expand All @@ -80,7 +80,7 @@ public static function fromAuthority(#[SensitiveParameter] Stringable|string|nul
*
* @param array{user? : ?string, pass? : ?string} $components
*/
public static function fromComponents(#[SensitiveParameter] array $components): self
public static function fromComponents(array $components): self
{
$components += ['user' => null, 'pass' => null];

Expand All @@ -93,7 +93,7 @@ public static function fromComponents(#[SensitiveParameter] array $components):
/**
* Creates a new instance from an encoded string.
*/
public static function new(#[SensitiveParameter] Stringable|string|null $value = null): self
public static function new(Stringable|string|null $value = null): self
{
if ($value instanceof UriComponentInterface) {
$value = $value->value();
Expand Down Expand Up @@ -185,7 +185,7 @@ public function withPass(#[SensitiveParameter] Stringable|string|null $password)
*
* Create a new instance from a URI object.
*/
public static function createFromUri(#[SensitiveParameter] Psr7UriInterface|UriInterface $uri): self
public static function createFromUri(Psr7UriInterface|UriInterface $uri): self
{
return self::fromUri($uri);
}
Expand All @@ -200,7 +200,7 @@ public static function createFromUri(#[SensitiveParameter] Psr7UriInterface|UriI
*
* Create a new instance from an Authority object.
*/
public static function createFromAuthority(#[SensitiveParameter] AuthorityInterface|Stringable|string $authority): self
public static function createFromAuthority(AuthorityInterface|Stringable|string $authority): self
{
return self::fromAuthority($authority);
}
Expand All @@ -215,7 +215,7 @@ public static function createFromAuthority(#[SensitiveParameter] AuthorityInterf
*
* Creates a new instance from an encoded string.
*/
public static function createFromString(#[SensitiveParameter] Stringable|string $userInfo): self
public static function createFromString(Stringable|string $userInfo): self
{
return self::new($userInfo);
}
Expand Down
2 changes: 0 additions & 2 deletions components/Modifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ final public function __construct(protected readonly Psr7UriInterface|UriInterfa
}

/**
* @param Stringable|string $uri
* @param UriFactoryInterface|null $uriFactory Deprecated, will be removed in the next major release
*
* @return static
*/
public static function from(Stringable|string $uri, ?UriFactoryInterface $uriFactory = null): static
{
Expand Down
12 changes: 6 additions & 6 deletions components/ModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -845,18 +845,18 @@ public static function idnUriProvider(): iterable
];

yield 'idn host are changed' => [
'expected' => "http://bébé.be",
'input' => "http://xn--bb-bjab.be",
'expected' => 'http://bébé.be',
'input' => 'http://xn--bb-bjab.be',
];

yield 'idn host are the same' => [
'expected' => "http://bébé.be",
'input' => "http://bébé.be",
'expected' => 'http://bébé.be',
'input' => 'http://bébé.be',
];

yield 'the rest of the URI is not affected and uses RFC3986 rules' => [
'expected' => "http://bébé.be?q=toto%20le%20h%C3%A9ros",
'input' => "http://bébé.be:80?q=toto le héros",
'expected' => 'http://bébé.be?q=toto%20le%20h%C3%A9ros',
'input' => 'http://bébé.be:80?q=toto le héros',
];
}

Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@
"ext-fileinfo": "*",
"ext-gmp": "*",
"ext-intl": "*",
"friendsofphp/php-cs-fixer": "^3.59.3",
"guzzlehttp/psr7": "^2.6.2",
"laminas/laminas-diactoros": "^3.3.1",
"nyholm/psr7": "^1.8.1",
"friendsofphp/php-cs-fixer": "^3.64.0",
"guzzlehttp/psr7": "^2.7.0",
"laminas/laminas-diactoros": "^3.4.0",
"nyholm/psr7": "^1.8.2",
"phpbench/phpbench": "^1.3.1",
"phpstan/phpstan": "^1.11.7",
"phpstan/phpstan-deprecation-rules": "^1.2.0",
"phpstan/phpstan": "^1.12.4",
"phpstan/phpstan-deprecation-rules": "^1.2.1",
"phpstan/phpstan-phpunit": "^1.4.0",
"phpstan/phpstan-strict-rules": "^1.6.0",
"phpunit/phpunit": "^10.5.17 || ^11.2.6",
"phpunit/phpunit": "^10.5.17 || ^11.3.6",
"psr/http-factory": "^1.1.0",
"psr/http-message": "^1.1.0 || ^2.0",
"symfony/var-dumper": "^6.4.9",
"symfony/var-dumper": "^6.4.11",
"uri-templates/uritemplate-test": "dev-master"
},
"repositories": [
Expand Down
3 changes: 2 additions & 1 deletion interfaces/IPv4/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use function preg_match;
use function str_ends_with;
use function substr;

use const FILTER_FLAG_IPV4;
use const FILTER_FLAG_IPV6;
use const FILTER_VALIDATE_IP;
Expand Down Expand Up @@ -142,7 +143,7 @@ public function to6to4(Stringable|string|null $host): ?string
explode('.', $host)
);

return '['.self::IPV6_6TO4_PREFIX . $parts[0] . $parts[1] . ':' . $parts[2] . $parts[3] . '::]';
return '['.self::IPV6_6TO4_PREFIX.$parts[0].$parts[1].':'.$parts[2].$parts[3].'::]';
}

public function toIPv4MappedIPv6(Stringable|string|null $host): ?string
Expand Down
3 changes: 1 addition & 2 deletions interfaces/IPv4/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function testConvertToDecimal(
string $hexadecimal,
string $sixToFour,
string $ipv4Mapped,
): void
{
): void {
self::assertSame($octal, Converter::fromGMP()->toOctal($input));
self::assertSame($octal, Converter::fromNative()->toOctal($input));
self::assertSame($octal, Converter::fromBCMath()->toOctal($input));
Expand Down
25 changes: 17 additions & 8 deletions interfaces/IPv6/Converter.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
<?php

/**
* League.Uri (https://uri.thephpleague.com)
*
* (c) Ignace Nyamagana Butera <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace League\Uri\IPv6;

use Stringable;
use ValueError;

use const FILTER_FLAG_IPV6;
use const FILTER_VALIDATE_IP;

use function filter_var;
use function inet_pton;
use function implode;
use function inet_pton;
use function str_split;
use function strtolower;
use function unpack;

use const FILTER_FLAG_IPV6;
use const FILTER_VALIDATE_IP;

final class Converter
{
/**
Expand All @@ -40,7 +49,7 @@ public static function expandIp(string $ipAddress): string
throw new ValueError('The submitted IP is not a valid IPv6 address.');
}

$hex = (array) unpack("H*hex", (string) inet_pton($ipAddress));
$hex = (array) unpack('H*hex', (string) inet_pton($ipAddress));

return implode(':', str_split(strtolower($hex['hex'] ?? ''), 4));
}
Expand Down Expand Up @@ -80,7 +89,7 @@ private static function build(array $components): string
$components['ipAddress'] ??= null;
$components['zoneIdentifier'] ??= null;

if (null === $components['ipAddress']){
if (null === $components['ipAddress']) {
return '';
}

Expand All @@ -97,12 +106,12 @@ private static function build(array $components): string
*/
private static function parse(Stringable|string|null $host): array
{
if ($host === null) {
if (null === $host) {
return ['ipAddress' => null, 'zoneIdentifier' => null];
}

$host = (string) $host;
if ($host === '') {
if ('' === $host) {
return ['ipAddress' => null, 'zoneIdentifier' => null];
}

Expand Down
13 changes: 11 additions & 2 deletions interfaces/IPv6/ConverterTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/**
* League.Uri (https://uri.thephpleague.com)
*
* (c) Ignace Nyamagana Butera <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace League\Uri\IPv6;
Expand Down Expand Up @@ -59,9 +68,9 @@ public function testItFailsToCompressANonIpv6(string $invalidIp): void
#[DataProvider('invalidIpv6')]
public function testItFailsToExpandANonIpv6(string $invalidIp): void
{
$this->expectException(ValueError::class);
$this->expectException(ValueError::class);

Converter::expandIp($invalidIp);
Converter::expandIp($invalidIp);
}

public static function invalidIpv6(): iterable
Expand Down
Loading

0 comments on commit b0f4ec5

Please sign in to comment.