Skip to content

Commit 23c03cb

Browse files
committed
patch
1 parent 5cc441f commit 23c03cb

File tree

6 files changed

+49
-13
lines changed

6 files changed

+49
-13
lines changed

src/Client.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,33 @@ public function guessType(string $target): ?array
9292
if (!$target) {
9393
return null;
9494
}
95-
if (str_contains($target, ':')) {
96-
$target = CIDR::filterIp6($target);
97-
return $target ? [self::IPV6, $target] : null;
95+
if (str_contains($target, '/') && ($cidr = CIDR::cidrToRange($target))) {
96+
if (str_contains($cidr[0], ':') || str_contains($cidr[1], ':')) {
97+
if ($target = CIDR::filterIp6($cidr[0])) {
98+
return [self::IPV6, $target];
99+
}
100+
}
101+
if (str_contains($cidr[0], '.') || str_contains($cidr[1], '.')) {
102+
if ($target = CIDR::filterIp4($cidr[0])) {
103+
return [self::IPV4, $target];
104+
}
105+
}
98106
}
99107
if (preg_match('~^(?:ASN?)?([0-9]+)$~i', $target, $match)) {
100108
$target = $match[1] > 0 && $match[1] <= AsnService::MAX_INTEGER
101109
? $match[1]
102110
: null;
103111
return $target ? [self::ASN, $target] : null;
104112
}
105-
if ($ip4 = CIDR::filterIp4($target)) {
106-
return [self::IPV4, $ip4];
113+
if (str_contains($target, ':') && ($ip6 = CIDR::filterIp6($target))) {
114+
return [self::IPV6, $ip6];
107115
}
108116
if (!str_contains($target, '.')) {
109117
return null;
110118
}
119+
if ($ip4 = CIDR::filterIp4($target)) {
120+
return [self::IPV4, $ip4];
121+
}
111122
$target = idn_to_ascii($target)?:null;
112123
if (!$target) {
113124
return null;

src/Interfaces/RdapResponseInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
namespace ArrayAccess\RdapClient\Interfaces;
55

6-
interface RdapResponseInterface
6+
use JsonSerializable;
7+
8+
interface RdapResponseInterface extends JsonSerializable
79
{
810
const CONTENT_TYPE = 'application/rdap+json';
911

src/Protocols/RdapRequestProtocol.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function withRdapSearchURL(string $url) : static
8585
// validate target
8686
$path = array_pop($targetUrl);
8787
$searchPath = rtrim($this->getProtocol()->getSearchPath(), '/');
88-
if (str_ends_with($searchPath, $path)) {
88+
if (!str_ends_with($searchPath, $path)) {
8989
throw new MismatchProtocolBehaviorException(
9090
'Target RDAP search path is mismatch'
9191
);

src/Response/Abstracts/AbstractResponse.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,9 @@ public function getProtocol(): RdapProtocolInterface
7070
{
7171
return $this->protocol;
7272
}
73+
74+
public function jsonSerialize() : mixed
75+
{
76+
return json_decode($this->getResponseJson(), true);
77+
}
7378
}

src/Response/Data/Definitions/RdapCustomConformanceData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333

3434
public function rootOnly(): bool
3535
{
36-
return true;
36+
return false;
3737
}
3838

3939
public function getAllowedKeys(): ?array

src/Response/Definitions/AbstractResponseDefinition.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace ArrayAccess\RdapClient\Response\Definitions;
55

66
use ArrayAccess\RdapClient\Exceptions\InvalidDataTypeException;
7+
use ArrayAccess\RdapClient\Exceptions\MismatchProtocolBehaviorException;
78
use ArrayAccess\RdapClient\Interfaces\RdapRequestInterface;
89
use ArrayAccess\RdapClient\Interfaces\RdapResponseDefinitionInterface;
910
use ArrayAccess\RdapClient\Interfaces\RdapResponseInterface;
@@ -651,18 +652,35 @@ public function getRelatedRequest(): ?RdapRequestInterface
651652
}
652653
$this->relatedRequest = false;
653654
foreach (($this->getLinks()?->getLinks()??[]) as $link) {
654-
if ($link->getRel()?->getPlainData() === 'related'
655-
&& ($url = $link->getHref()?->getPlainData())
656-
) {
657-
return $this->relatedRequest = $this
655+
if ($link->getRel()?->getPlainData() !== 'related') {
656+
continue;
657+
}
658+
$url = $link->getValue()?->getPlainData();
659+
if ($url && ($this->relatedRequest = $this->createObjectRdapRequestURL($url)??false)) {
660+
return $this->relatedRequest;
661+
}
662+
$url = $link->getHref()?->getPlainData();
663+
if ($url && ($this->relatedRequest = $this->createObjectRdapRequestURL($url)??false)) {
664+
return $this->relatedRequest;
665+
}
666+
}
667+
return null;
668+
}
669+
670+
private function createObjectRdapRequestURL(?string $url): ?RdapRequestInterface
671+
{
672+
if ($url && preg_match('~^https?://~i', $url)) {
673+
try {
674+
return $this
658675
->getRdapResponseObject()
659676
->getRequest()
660677
->withRdapSearchURL($url);
678+
} catch (MismatchProtocolBehaviorException) {
661679
}
662680
}
681+
663682
return null;
664683
}
665-
666684
public function __set(string $name, $value): void
667685
{
668686
// pass

0 commit comments

Comments
 (0)