Skip to content

Commit 2548f75

Browse files
ryzokukentargos
authored andcommitted
src: use UTF-8 for naming interfaces in unix
Use a UTF-8 encoded string for naming interfaces in unix, instead of using Latin-1, as had been done on windows previously. PR-URL: #21926 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6b6a26b commit 2548f75

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/node_os.cc

+5-7
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,13 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
257257
for (i = 0; i < count; i++) {
258258
const char* const raw_name = interfaces[i].name;
259259

260-
// On Windows, the interface name is the UTF8-encoded friendly name and may
261-
// contain non-ASCII characters. On UNIX, it's just a binary string with
262-
// no particular encoding but we treat it as a one-byte Latin-1 string.
263-
#ifdef _WIN32
260+
// Use UTF-8 on both Windows and Unixes (While it may be true that UNIX
261+
// systems are somewhat encoding-agnostic here, it’s more than reasonable
262+
// to assume UTF8 as the default as well. It’s what people will expect if
263+
// they name the interface from any input that uses UTF-8, which should be
264+
// the most frequent case by far these days.)
264265
name = String::NewFromUtf8(env->isolate(), raw_name,
265266
v8::NewStringType::kNormal).ToLocalChecked();
266-
#else
267-
name = OneByteString(env->isolate(), raw_name);
268-
#endif
269267

270268
if (ret->Has(env->context(), name).FromJust()) {
271269
ifarr = Local<Array>::Cast(ret->Get(name));

0 commit comments

Comments
 (0)