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 f2a4747 commit 48e741e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
3 changes: 2 additions & 1 deletion 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 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 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 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
20 changes: 10 additions & 10 deletions UriString.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static function build(array $components): string
}

/**
* Generate a URI string representation based on RFC3986 algorithm
* Generate a URI string representation based on RFC3986 algorithm.
*
* valid URI component MUST be provided without their URI delimiters
* but properly encoded.
Expand Down Expand Up @@ -345,23 +345,23 @@ public static function parse(Stringable|string|int $uri): array
preg_match(self::REGEXP_URI_PARTS, $uri, $parts);
$parts += ['query' => '', 'fragment' => ''];

if (':' === $parts['scheme'] || 1 !== preg_match(self::REGEXP_URI_SCHEME, $parts['scontent'])) {
if (':' === ($parts['scheme'] ?? null) || 1 !== preg_match(self::REGEXP_URI_SCHEME, $parts['scontent'] ?? '')) {
throw new SyntaxError(sprintf('The uri `%s` contains an invalid scheme', $uri));
}

if ('' === $parts['scheme'].$parts['authority'] && 1 === preg_match(self::REGEXP_INVALID_PATH, $parts['path'])) {
if ('' === ($parts['scheme'] ?? '').($parts['authority'] ?? '') && 1 === preg_match(self::REGEXP_INVALID_PATH, $parts['path'] ?? '')) {
throw new SyntaxError(sprintf('The uri `%s` contains an invalid path.', $uri));
}

/** @var ComponentMap $components */
$components = array_merge(
self::URI_COMPONENTS,
'' === $parts['authority'] ? [] : self::parseAuthority($parts['acontent']),
'' === ($parts['authority'] ?? null) ? [] : self::parseAuthority($parts['acontent'] ?? null),
[
'path' => $parts['path'],
'scheme' => '' === $parts['scheme'] ? null : $parts['scontent'],
'query' => '' === $parts['query'] ? null : $parts['qcontent'],
'fragment' => '' === $parts['fragment'] ? null : $parts['fcontent'],
'path' => $parts['path'] ?? '',
'scheme' => '' === ($parts['scheme'] ?? null) ? null : ($parts['scontent'] ?? null),
'query' => '' === $parts['query'] ? null : ($parts['qcontent'] ?? null),
'fragment' => '' === $parts['fragment'] ? null : ($parts['fcontent'] ?? null),
]
);

Expand Down Expand Up @@ -399,7 +399,7 @@ public static function parseAuthority(Stringable|string|null $authority): array
$matches += ['port' => ''];

$components['port'] = self::filterPort($matches['port']);
$components['host'] = self::filterHost($matches['host']);
$components['host'] = self::filterHost($matches['host'] ?? '');

return $components;
}
Expand Down Expand Up @@ -460,7 +460,7 @@ private static function filterHost(string $host): string
}

/**
* Throws if the host is not a registered name and not a valid IDN host
* Throws if the host is not a registered name and not a valid IDN host.
*
* @link https://tools.ietf.org/html/rfc3986#section-3.2.2
*
Expand Down

0 comments on commit 48e741e

Please sign in to comment.