Stricter string to integer conversion in TDF scripts

This commit is contained in:
Nav
2024-02-12 19:14:25 +00:00
parent fdf7b936e2
commit a4c08c1b0a

View File

@@ -9,7 +9,11 @@ class StringService
return null; return null;
} }
return stristr($value, '0x') !== false ? (int) hexdec($value) : (int) $value; if (stripos($value, '0x') === 0) {
return ctype_xdigit(substr($value, 2)) ? (int) hexdec($value) : null;
}
return ctype_digit($value) ? (int) $value : null;
} }
public function tryIntToHex(?int $value, int $pad = 0): string public function tryIntToHex(?int $value, int $pad = 0): string