diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2014-11-03 16:42:07 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2014-11-05 20:39:24 +0100 |
commit | e13663d647d036d49872b7ab99a5fb7b9d9268df (patch) | |
tree | 063b9405d368defe79dca3ed4f79bd1661a46f49 /src/node_os.cc | |
parent | 7ab73ff735b26207c99b4259c4fd7c1aa8c23643 (diff) | |
download | android-node-v8-e13663d647d036d49872b7ab99a5fb7b9d9268df.tar.gz android-node-v8-e13663d647d036d49872b7ab99a5fb7b9d9268df.tar.bz2 android-node-v8-e13663d647d036d49872b7ab99a5fb7b9d9268df.zip |
src: network interface names are UTF-8 encoded
Fixes a bug that was introduced in commit f674b09 when v8::String::New()
calls were replaced with calls to one-byte, two-byte and UTF-8 versions.
It turns out that for network interface names, using a one-byte encoding
can produce the wrong results on Windows. Use UTF-8 instead.
Libuv on Windows correctly encodes non-ASCII characters in the interface
name as UTF-8. On Unices however, the interface name is just a binary
string with no particular encoding; that's why on UNIX platforms, we
keep interpreting it as a one-byte string.
Fixes joyent/node#8633.
PR-URL: https://github.com/node-forward/node/pull/44
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Diffstat (limited to 'src/node_os.cc')
-rw-r--r-- | src/node_os.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/node_os.cc b/src/node_os.cc index 53d3d21e56..9341ee67e6 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -231,7 +231,17 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) { } for (i = 0; i < count; i++) { - name = OneByteString(env->isolate(), interfaces[i].name); + const char* const raw_name = interfaces[i].name; + + // On Windows, the interface name is the UTF8-encoded friendly name and may + // contain non-ASCII characters. On UNIX, it's just a binary string with + // no particular encoding but we treat it as a one-byte Latin-1 string. +#ifdef _WIN32 + name = String::NewFromUtf8(env->isolate(), raw_name); +#else + name = OneByteString(env->isolate(), raw_name); +#endif + if (ret->Has(name)) { ifarr = Local<Array>::Cast(ret->Get(name)); } else { |