Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.hostname() returning as '????' #27848

Closed
kumamit08 opened this issue May 24, 2019 · 1 comment
Closed

os.hostname() returning as '????' #27848

kumamit08 opened this issue May 24, 2019 · 1 comment
Labels
os Issues and PRs related to the os subsystem.

Comments

@kumamit08
Copy link

Can't recognize Chinese if set pc name in Chinese

Steps to reproduce

  1. set PC name as "-发动机”
  2. in log file --> os.hostname() give result as '????' and not chinese PC name.
@addaleax addaleax transferred this issue from nodejs/help May 24, 2019
addaleax added a commit to addaleax/node that referenced this issue May 24, 2019
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: nodejs#27848
@lpinca lpinca added the os Issues and PRs related to the os subsystem. label May 25, 2019
targos pushed a commit that referenced this issue May 28, 2019
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>
@aaclayton
Copy link

This does not appear to be fixed, or has regressed:

Unless I'm misunderstanding, the change which was proposed by this merge request does not seem to function properly. See the below simple example on 14.15.1

image

I assigned this Windows laptop name as ANDREW-ü-LAPTOP and obtain "ANDREW-�-LAPTOP" as the reported hostname.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os Issues and PRs related to the os subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants