Skip to content

Commit 587ad2f

Browse files
committed
fix bug
1 parent 23c03cb commit 587ad2f

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ public function guessType(string $target): ?array
9494
}
9595
if (str_contains($target, '/') && ($cidr = CIDR::cidrToRange($target))) {
9696
if (str_contains($cidr[0], ':') || str_contains($cidr[1], ':')) {
97-
if ($target = CIDR::filterIp6($cidr[0])) {
97+
if (CIDR::filterIp6($cidr[0]) && CIDR::filterIp6($cidr[1])) {
9898
return [self::IPV6, $target];
9999
}
100100
}
101101
if (str_contains($cidr[0], '.') || str_contains($cidr[1], '.')) {
102-
if ($target = CIDR::filterIp4($cidr[0])) {
102+
if (CIDR::filterIp4($cidr[0]) && CIDR::filterIp4($cidr[1])) {
103103
return [self::IPV4, $target];
104104
}
105105
}

src/Interfaces/RdapResponseInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function getAllowedKeys() : ?array;
1919

2020
public function getResponseJson(): string;
2121

22+
public function getResponseArray() : array;
23+
2224
public function getRequest(): RdapRequestInterface;
2325

2426
public function getProtocol(): RdapProtocolInterface;

src/Response/Abstracts/AbstractResponse.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,24 @@ abstract class AbstractResponse implements RdapResponseInterface
1919
{
2020
use AllowedKeyDataTraits;
2121

22+
/**
23+
* @var string original response JSON
24+
*/
2225
protected string $responseJson;
2326

27+
/**
28+
* @var array decoded json
29+
*/
30+
protected array $responseArray = [];
31+
32+
/**
33+
* @var RdapRequestInterface request object
34+
*/
2435
protected RdapRequestInterface $request;
2536

37+
/**
38+
* @var RdapProtocolInterface protocol object
39+
*/
2640
protected RdapProtocolInterface $protocol;
2741

2842
public function __construct(
@@ -54,13 +68,19 @@ private function assertResponse(string $responseJson): void
5468
'Response is not valid json content'
5569
);
5670
}
71+
$this->responseArray = $responseJson;
5772
}
5873

5974
public function getResponseJson(): string
6075
{
6176
return $this->responseJson;
6277
}
6378

79+
public function getResponseArray(): array
80+
{
81+
return $this->responseArray;
82+
}
83+
6484
public function getRequest(): RdapRequestInterface
6585
{
6686
return $this->request;
@@ -71,8 +91,8 @@ public function getProtocol(): RdapProtocolInterface
7191
return $this->protocol;
7292
}
7393

74-
public function jsonSerialize() : mixed
94+
public function jsonSerialize() : array
7595
{
76-
return json_decode($this->getResponseJson(), true);
96+
return $this->responseArray;
7797
}
7898
}

src/Response/Definitions/AbstractResponseDefinition.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,9 @@ public function getRelatedRequest(): ?RdapRequestInterface
655655
if ($link->getRel()?->getPlainData() !== 'related') {
656656
continue;
657657
}
658-
$url = $link->getValue()?->getPlainData();
659-
if ($url && ($this->relatedRequest = $this->createObjectRdapRequestURL($url)??false)) {
660-
return $this->relatedRequest;
658+
$type = $link->getType()?->getPlainData();
659+
if (!$type || !str_contains($type, 'application/rdap+json')) {
660+
continue;
661661
}
662662
$url = $link->getHref()?->getPlainData();
663663
if ($url && ($this->relatedRequest = $this->createObjectRdapRequestURL($url)??false)) {

src/Services/Ipv4Service.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function normalizeSource(string $target): string
4545
&& ((int) $explode[1]) <= 32
4646
&& str_contains($explode[0], '.')
4747
&& strlen($explode[0]) <= 15
48-
&& strlen($explode[0]) <= 7
48+
&& strlen($explode[0]) >= 7
4949
&& ($_target = $this->normalize($explode[0]))
5050
) {
5151
return "$_target/$explode[1]";
@@ -110,6 +110,9 @@ public function getRdapURL(string $target) : ?string
110110

111111
public function normalize(string $target): ?string
112112
{
113+
if (str_contains($target, '/')) {
114+
return $this->normalizeSource($target);
115+
}
113116
if (!preg_match(
114117
'~^(?:[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',
115118
$target

src/Services/Ipv6Service.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public function normalize(string $target): ?string
3535
if (str_contains($target, ':')) {
3636
return null;
3737
}
38+
if (str_contains($target, '/')) {
39+
return $this->normalizeSource($target);
40+
}
3841
$target = CIDR::filter($target);
3942
if (!$target) {
4043
return null;

0 commit comments

Comments
 (0)