Skip to content

Commit 1ecd825

Browse files
committed
Fix IPv6Address#setShorts(), add ctype dependency
1 parent 887591d commit 1ecd825

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"license": "MIT",
55
"keywords": ["dns"],
66
"require": {
7-
"php": ">=7.0"
7+
"php": ">=7.0",
8+
"ext-ctype": "*"
89
},
910
"autoload": {
1011
"psr-4": {

src/Records/Types/IPv4Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function setOctets(array $octets)
8181
}
8282

8383
foreach ($octets as &$octet) {
84-
if (\strspn((string)$octet, "0123456789") !== \strlen((string)$octet) || $octet < 0x00 || $octet > 0xff) {
84+
if ((!\is_int($octet) && !\ctype_digit((string)$octet)) || $octet < 0x00 || $octet > 0xff) {
8585
throw new \UnexpectedValueException('Octet list is not a valid IPv4 address: invalid octet value ' . $octet);
8686
}
8787

src/Records/Types/IPv6Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function setShorts(array $shorts)
145145
}
146146

147147
foreach ($shorts as &$short) {
148-
if (\strspn((string)$short, "0123456789") !== \strlen($short) || $short < 0x0000 || $short > 0xffff) {
148+
if ((!\is_int($short) && !\ctype_digit((string)$short)) || $short < 0x0000 || $short > 0xffff) {
149149
throw new \UnexpectedValueException('Short list is not a valid IPv6 address: invalid short value ' . $short);
150150
}
151151

0 commit comments

Comments
 (0)