Skip to content

hostname: preserve non-UTF-8 names in output - #15405

Open
limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/hostname-non-utf8
Open

limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/hostname-non-utf8

Conversation

@limadog9

Copy link
Copy Markdown
Contributor

Preserve hostname bytes in full, short, and domain output. Adds integration tests using isolated namespaces.

Closes #14276.

Comment thread src/uu/hostname/src/hostname.rs Outdated
if matches.get_flag(OPT_SHORT) || matches.get_flag(OPT_DOMAIN) {
let mut it = hostname.char_indices().filter(|&ci| ci.1 == '.');
if let Some(ci) = it.next() {
let hostname_bytes = os_str_as_bytes(&hostname)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on windows this now errors on a non-UTF-8 name instead of printing it lossy, could you please use os_str_as_bytes_lossy?

let ts = TestScenario::new("hostname");
ts.cmd("unshare")
.args(&["-Ur", "-u", "sh", "-c"])
.arg(r#"bin=$1; "$bin" hostname "$2" || exit; shift 2; exec "$bin" hostname "$@""#)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one-liner is hard to read, could you please add a short comment on what it does?

@limadog9
limadog9 force-pushed the fix/hostname-non-utf8 branch from a5202f0 to b27de9d Compare October 24, 2026 14:29
@sylvestre
sylvestre force-pushed the fix/hostname-non-utf8 branch from b27de9d to 42a8d2f Compare October 25, 2026 09:28

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hostname: hostname doesn't accept invalid utf-8

2 participants