ardaku / whoami

Rust crate to get the current user and environment.
Apache License 2.0
195 stars 31 forks source link

Hostname is all capitals on Windows #39

Closed WilliamVenner closed 2 years ago

WilliamVenner commented 2 years ago

Describe the bug The hostname returned by whoami::hostname is in all capitals on Windows.

To Reproduce

[dependencies]
whoami = "1"
hostname = "0.3"
fn main() {
    println!("whoami {:?}", whoami::hostname());
    println!("hostname {:?}", hostname::get());
}

Expected behavior The hostname should be returned in the correct casing.

Screenshots image

WilliamVenner commented 2 years ago

This is on Windows 11 BTW. Not sure about the others

AldaronLau commented 2 years ago

@WilliamVenner Thank you for reporting! I'll look into it.

WilliamVenner commented 2 years ago

Notably, whoami::devicename() returns the correct casing. Maybe this is the intended behaviour of hostnames on Windows?

AldaronLau commented 2 years ago

After looking at it, I believe the current behavior is correct. The difference between hostname() and devicename() is that devicename() takes into account "fancy" styling which generally ignored by hostnames (such as casing on Windows, and on Linux can also include spaces and punctuation).

It might even make more sense to normalize the hostname returned by the OS to lowercase across all platforms (since Windows is the only one that returns it in all capitals; other platforms return the case-insensitive string in all lowercase).

WilliamVenner commented 2 years ago

Ok yeah, that makes sense. Thank you!