Skip to content

Conversation

@nvwls
Copy link
Contributor

@nvwls nvwls commented Dec 27, 2025

Description

In RHEL 10 (and other modern systemd-based distributions), the hostnamectl command has been updated to include visual icons using UTF-8 characters for the Chassis field.

This change is part of the upstream systemd project's effort to make the CLI output more visually informative for users. Instead of just seeing the word "laptop" or "server," you now see a corresponding symbol.

This leads to following:

warning: JSON.generate: UTF-8 string passed as BINARY, this will raise an
encoding error in json 3.0

Related Issue

#1908

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • If Gemfile.lock has changed, I have used --conservative to do it and included the full output in the Description above.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

In RHEL 10 (and other modern systemd-based distributions), the hostnamectl
command has been updated to include visual icons using UTF-8 characters for
the Chassis field.

This change is part of the upstream systemd project's effort to make the CLI
output more visually informative for users. Instead of just seeing the word
"laptop" or "server," you now see a corresponding symbol.

This leads to following:
```
warning: JSON.generate: UTF-8 string passed as BINARY, this will raise an
encoding error in json 3.0
```

Signed-off-by: Joseph J Nuspl Jr <nuspl@nvwls.com>
@nvwls nvwls requested review from a team and jaymzh as code owners December 27, 2025 21:50
@sonarqubecloud
Copy link

key, val = line.split(": ", 2)

# strip visual icons produced by newer versions of systemd
val.gsub!(/ [^[:ascii]]*$/, "")
Copy link
Collaborator

@jaymzh jaymzh Dec 27, 2025

Choose a reason for hiding this comment

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

I like where you're going with this but non-ascii isn't quite what you want, which is why you're having to add anchors. This will grab all unicode+modifiers and squeeze the spaces:

irb(main):025> re = /\p{So}\p{Mn}*/u
=> /\p{So}\p{Mn}*/
irb(main):031> vals = ["Chassis: desktop 🖥️", "Chassis: 🖥️ desktop", "🖥️ Chassis: desktop"]
irb(main):033> vals.map { |val| val.gsub(re, "").squeeze(" ").strip }
=> ["Chassis: desktop", "Chassis: desktop", "Chassis: desktop"]

This handles all sort of cases they can throw at us without any unnecessary removals.

Suggested change
val.gsub!(/ [^[:ascii]]*$/, "")
val.gsub!(/\p{So}\p{Mn}*/u, "").squeeze(" ").strip

Ideally we would also add a unittest for this with those test cases....there's already a ton of hostname tests in spec/unit/plugins/hostname_spec.rb you can use as a template.

@johnmccrae johnmccrae added the Status: Waiting on Contributor A pull request that has unresolved requested actions from the author. label Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Waiting on Contributor A pull request that has unresolved requested actions from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants