Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayIterator committed Mar 10, 2024
1 parent 23c03cb commit 587ad2f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ public function guessType(string $target): ?array
}
if (str_contains($target, '/') && ($cidr = CIDR::cidrToRange($target))) {
if (str_contains($cidr[0], ':') || str_contains($cidr[1], ':')) {
if ($target = CIDR::filterIp6($cidr[0])) {
if (CIDR::filterIp6($cidr[0]) && CIDR::filterIp6($cidr[1])) {
return [self::IPV6, $target];
}
}
if (str_contains($cidr[0], '.') || str_contains($cidr[1], '.')) {
if ($target = CIDR::filterIp4($cidr[0])) {
if (CIDR::filterIp4($cidr[0]) && CIDR::filterIp4($cidr[1])) {
return [self::IPV4, $target];
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Interfaces/RdapResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function getAllowedKeys() : ?array;

public function getResponseJson(): string;

public function getResponseArray() : array;

public function getRequest(): RdapRequestInterface;

public function getProtocol(): RdapProtocolInterface;
Expand Down
24 changes: 22 additions & 2 deletions src/Response/Abstracts/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,24 @@ abstract class AbstractResponse implements RdapResponseInterface
{
use AllowedKeyDataTraits;

/**
* @var string original response JSON
*/
protected string $responseJson;

/**
* @var array decoded json
*/
protected array $responseArray = [];

/**
* @var RdapRequestInterface request object
*/
protected RdapRequestInterface $request;

/**
* @var RdapProtocolInterface protocol object
*/
protected RdapProtocolInterface $protocol;

public function __construct(
Expand Down Expand Up @@ -54,13 +68,19 @@ private function assertResponse(string $responseJson): void
'Response is not valid json content'
);
}
$this->responseArray = $responseJson;
}

public function getResponseJson(): string
{
return $this->responseJson;
}

public function getResponseArray(): array
{
return $this->responseArray;
}

public function getRequest(): RdapRequestInterface
{
return $this->request;
Expand All @@ -71,8 +91,8 @@ public function getProtocol(): RdapProtocolInterface
return $this->protocol;
}

public function jsonSerialize() : mixed
public function jsonSerialize() : array
{
return json_decode($this->getResponseJson(), true);
return $this->responseArray;
}
}
6 changes: 3 additions & 3 deletions src/Response/Definitions/AbstractResponseDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ public function getRelatedRequest(): ?RdapRequestInterface
if ($link->getRel()?->getPlainData() !== 'related') {
continue;
}
$url = $link->getValue()?->getPlainData();
if ($url && ($this->relatedRequest = $this->createObjectRdapRequestURL($url)??false)) {
return $this->relatedRequest;
$type = $link->getType()?->getPlainData();
if (!$type || !str_contains($type, 'application/rdap+json')) {
continue;
}
$url = $link->getHref()?->getPlainData();
if ($url && ($this->relatedRequest = $this->createObjectRdapRequestURL($url)??false)) {
Expand Down
5 changes: 4 additions & 1 deletion src/Services/Ipv4Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function normalizeSource(string $target): string
&& ((int) $explode[1]) <= 32
&& str_contains($explode[0], '.')
&& strlen($explode[0]) <= 15
&& strlen($explode[0]) <= 7
&& strlen($explode[0]) >= 7
&& ($_target = $this->normalize($explode[0]))
) {
return "$_target/$explode[1]";
Expand Down Expand Up @@ -110,6 +110,9 @@ public function getRdapURL(string $target) : ?string

public function normalize(string $target): ?string
{
if (str_contains($target, '/')) {
return $this->normalizeSource($target);
}
if (!preg_match(
'~^(?:[01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])(?:\.(?:[01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){3}$~x',
$target
Expand Down
3 changes: 3 additions & 0 deletions src/Services/Ipv6Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public function normalize(string $target): ?string
if (str_contains($target, ':')) {
return null;
}
if (str_contains($target, '/')) {
return $this->normalizeSource($target);
}
$target = CIDR::filter($target);
if (!$target) {
return null;
Expand Down

0 comments on commit 587ad2f

Please sign in to comment.