danielzzz / node-ping

a poor man's ping library (using udp scanning) for node
MIT License
336 stars 105 forks source link

Not works in Japanese locale environment #129

Closed eternalharvest closed 3 years ago

eternalharvest commented 3 years ago

Summary

Thank you for providing such a useful library, but in Japanese locale environment it's not working with following error.

/home/takuya/work/wol/node_modules/ping/lib/parser/mac.js:42
        this._times.push(parseFloat(match[1], 10));
                                         ^

TypeError: Cannot read property '1' of null
    at LinuxParser.MacParser._processBody (/home/takuya/work/wol/node_modules/ping/lib/parser/mac.js:42:42)
    at LinuxParser._processBody (/home/takuya/work/wol/node_modules/ping/lib/parser/linux.js:45:38)
    at LinuxParser.parser.eat (/home/takuya/work/wol/node_modules/ping/lib/parser/base.js:133:14)
    at /home/takuya/work/wol/node_modules/underscore/underscore.js:723:21
    at Function.each (/home/takuya/work/wol/node_modules/underscore/underscore.js:1310:9)
    at ChildProcess.<anonymous> (/home/takuya/work/wol/node_modules/ping/lib/ping-promise.js:87:12)
    at Object.onceWrapper (events.js:422:26)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1051:16)
    at Socket.<anonymous> (internal/child_process.js:442:11)

Since ping command supports i18n message translation, some regular expression seems not matching. Here is my ping results to google.com.

PING google.com (172.217.25.78) 56(84) バイトのデータ
64 バイト応答 送信元 nrt13s50-in-f14.1e100.net (172.217.25.78): icmp_seq=1 ttl=115 時間=16.1ミリ秒
64 バイト応答 送信元 nrt13s50-in-f14.1e100.net (172.217.25.78): icmp_seq=2 ttl=115 時間=16.1ミリ秒
64 バイト応答 送信元 nrt13s50-in-f14.1e100.net (172.217.25.78): icmp_seq=3 ttl=115 時間=15.8ミリ秒

And this is the results when I run ping command with environment variable LANG=C

PING google.com (216.58.197.206) 56(84) bytes of data.
64 bytes from nrt13s48-in-f206.1e100.net (216.58.197.206): icmp_seq=1 ttl=115 time=38.6 ms
64 bytes from nrt13s48-in-f206.1e100.net (216.58.197.206): icmp_seq=2 ttl=115 time=50.9 ms
64 bytes from nrt13s48-in-f206.1e100.net (216.58.197.206): icmp_seq=3 ttl=115 time=23.9 ms

Environment

mondwan commented 3 years ago

I am not sure whether this fix will apply to some hosts does not include C. Anyway, let's keep an eye on that issue