Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1da5acb

Browse filesBrowse files
addaleaxtargos
authored andcommitted
os: assume UTF-8 for hostname
Do not assume Latin-1, but rather UTF-8 for the result of getting the OS hostname. While in 99 % of cases these strings are stored in ASCII, the OS does not enforce an encoding on its own, and apparently the hostname is sometimes set to non-ASCII data (despite at least some versions of hostname(1) rejecting such input, making it even harder to write a test for this which would already require root privileges). In any case, these are short strings, so assuming UTF-8 comes with no significant overhead. Fixes: #27848 PR-URL: #27849 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
1 parent e8fa067 commit 1da5acb
Copy full SHA for 1da5acb

File tree

Expand file treeCollapse file tree

1 file changed

+10
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-3
lines changed
Open diff view settings
Collapse file

‎src/node_os.cc‎

Copy file name to clipboardExpand all lines: src/node_os.cc
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ using v8::Integer;
4949
using v8::Isolate;
5050
using v8::Local;
5151
using v8::MaybeLocal;
52+
using v8::NewStringType;
5253
using v8::Null;
5354
using v8::Number;
5455
using v8::Object;
@@ -69,7 +70,9 @@ static void GetHostname(const FunctionCallbackInfo<Value>& args) {
6970
return args.GetReturnValue().SetUndefined();
7071
}
7172

72-
args.GetReturnValue().Set(OneByteString(env->isolate(), buf));
73+
args.GetReturnValue().Set(
74+
String::NewFromUtf8(env->isolate(), buf, NewStringType::kNormal)
75+
.ToLocalChecked());
7376
}
7477

7578

@@ -84,7 +87,9 @@ static void GetOSType(const FunctionCallbackInfo<Value>& args) {
8487
return args.GetReturnValue().SetUndefined();
8588
}
8689

87-
args.GetReturnValue().Set(OneByteString(env->isolate(), info.sysname));
90+
args.GetReturnValue().Set(
91+
String::NewFromUtf8(env->isolate(), info.sysname, NewStringType::kNormal)
92+
.ToLocalChecked());
8893
}
8994

9095

@@ -99,7 +104,9 @@ static void GetOSRelease(const FunctionCallbackInfo<Value>& args) {
99104
return args.GetReturnValue().SetUndefined();
100105
}
101106

102-
args.GetReturnValue().Set(OneByteString(env->isolate(), info.release));
107+
args.GetReturnValue().Set(
108+
String::NewFromUtf8(env->isolate(), info.release, NewStringType::kNormal)
109+
.ToLocalChecked());
103110
}
104111

105112

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.