fix: idn ping errors (#6662)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
iotux
2026-01-11 19:28:07 +08:00
committed by GitHub
co-authored by autofix-ci[bot]
parent c5675ae9eb
commit da693e01c7
2 changed files with 67 additions and 0 deletions
+10
View File
@@ -157,6 +157,16 @@ exports.pingAsync = function (
deadline = PING_GLOBAL_TIMEOUT_DEFAULT,
timeout = PING_PER_REQUEST_TIMEOUT_DEFAULT
) {
try {
const url = new URL(`http://${destAddr}`);
destAddr = url.hostname;
if (destAddr.startsWith("[") && destAddr.endsWith("]")) {
destAddr = destAddr.slice(1, -1);
}
} catch (e) {
// ignore
}
return new Promise((resolve, reject) => {
ping.promise
.probe(destAddr, {