diff --git a/src/Client.php b/src/Client.php index 9ab47d2..e63bd33 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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]; } } diff --git a/src/Interfaces/RdapResponseInterface.php b/src/Interfaces/RdapResponseInterface.php index 53589b2..3bb792b 100644 --- a/src/Interfaces/RdapResponseInterface.php +++ b/src/Interfaces/RdapResponseInterface.php @@ -19,6 +19,8 @@ public function getAllowedKeys() : ?array; public function getResponseJson(): string; + public function getResponseArray() : array; + public function getRequest(): RdapRequestInterface; public function getProtocol(): RdapProtocolInterface; diff --git a/src/Response/Abstracts/AbstractResponse.php b/src/Response/Abstracts/AbstractResponse.php index cd05b6c..69aa893 100644 --- a/src/Response/Abstracts/AbstractResponse.php +++ b/src/Response/Abstracts/AbstractResponse.php @@ -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( @@ -54,6 +68,7 @@ private function assertResponse(string $responseJson): void 'Response is not valid json content' ); } + $this->responseArray = $responseJson; } public function getResponseJson(): string @@ -61,6 +76,11 @@ public function getResponseJson(): string return $this->responseJson; } + public function getResponseArray(): array + { + return $this->responseArray; + } + public function getRequest(): RdapRequestInterface { return $this->request; @@ -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; } } diff --git a/src/Response/Definitions/AbstractResponseDefinition.php b/src/Response/Definitions/AbstractResponseDefinition.php index 40ede2c..d7a863e 100644 --- a/src/Response/Definitions/AbstractResponseDefinition.php +++ b/src/Response/Definitions/AbstractResponseDefinition.php @@ -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)) { diff --git a/src/Services/Ipv4Service.php b/src/Services/Ipv4Service.php index 405292f..07e4e5a 100644 --- a/src/Services/Ipv4Service.php +++ b/src/Services/Ipv4Service.php @@ -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]"; @@ -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 diff --git a/src/Services/Ipv6Service.php b/src/Services/Ipv6Service.php index 1bede67..11d8a0b 100644 --- a/src/Services/Ipv6Service.php +++ b/src/Services/Ipv6Service.php @@ -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;