% w --libxo json {"uptime-information": {"time-of-day":" 9:01PM","uptime":2667682,"days":30,"hours":21,"minutes":1,"seconds":22,"uptime-human":" 30 days, 21:01,","users":2,"load-average-1":0,25,"load-average-5":0,34,"load-average-15":0,30, "user-table": {"user-entry": [{"user":"vedranm","tty":"pts/1","from":"p508c7e40.dip0.t-ipconnect.de","login-time":" 8:44PM","command":"w --libxo json"}, {"user":"vedranm","tty":"pts/2","from":"tmux(40223).%0","login-time":"čet01PM","idle":20,"command":"btop"}]}}} This is not valid JSON. One can notice the values 0,25, 0,34, and 0,30; number separator is printed as comma, while JSON requires the dot to be used regardless of locale. Setting locale to en_US.utf-8 like % env LC_ALL=en_US.utf-8 w --libxo json will produce correct result. Other comands, such as ps, output numbers with decimals as strings (bug 265223) and avoid this issue.
thank you for the report, Vedran. My guess is that this will be wrong with any Locale that uses "," for… well, commas, and for any Software that produces floating point results. If the latter is the case it's a libxo bug, not a bug in how w(1) is using it.
That would be the correct observation. Other commands, e.g. ps(1), use strings for decimal numbers (bug 265223) and avoid this issue. Not sure if this is an intentional safety measure.
for completeness, can you please show the output of locale for the broken behaviour?
What locale are you using: hr_HR.ISO8859-2 or hr_HR.UTF-8?
Ah it does not matter hr_HR is the problem here,
(In reply to Mina Galić from comment #3) Sure. % locale LANG=hr_HR.UTF-8 LC_CTYPE="hr_HR.UTF-8" LC_COLLATE="hr_HR.UTF-8" LC_TIME="hr_HR.UTF-8" LC_NUMERIC="hr_HR.UTF-8" LC_MONETARY="hr_HR.UTF-8" LC_MESSAGES="hr_HR.UTF-8" LC_ALL= (In reply to Baptiste Daroussin from comment #5) That is correct.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=bd490be57438a82c22d1274bc58d51142b63f4a0 commit bd490be57438a82c22d1274bc58d51142b63f4a0 Author: Baptiste Daroussin <bapt@FreeBSD.org> AuthorDate: 2024-10-14 07:37:46 +0000 Commit: Baptiste Daroussin <bapt@FreeBSD.org> CommitDate: 2024-10-14 08:43:38 +0000 w(1): fix libxo output being locale dependant by being locale dependant the json export is invalid in locales where the separator for float is a comma. The Json and the XML are invalid for login-time when days contains contains characters which are not unicode. Forcing locale to be C, makes this json and xml output valid and also identical accross locales, so reliable for parsers PR: 276304 Reported by: Vedran Miletic <vedran@miletic.net> usr.bin/w/w.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=6c1a174e4c0a01a40aa1c06dfc07a37a31cabe33 commit 6c1a174e4c0a01a40aa1c06dfc07a37a31cabe33 Author: Baptiste Daroussin <bapt@FreeBSD.org> AuthorDate: 2024-10-14 07:37:46 +0000 Commit: Baptiste Daroussin <bapt@FreeBSD.org> CommitDate: 2024-10-23 07:25:50 +0000 w(1): fix libxo output being locale dependant by being locale dependant the json export is invalid in locales where the separator for float is a comma. The Json and the XML are invalid for login-time when days contains contains characters which are not unicode. Forcing locale to be C, makes this json and xml output valid and also identical accross locales, so reliable for parsers PR: 276304 Reported by: Vedran Miletic <vedran@miletic.net> (cherry picked from commit bd490be57438a82c22d1274bc58d51142b63f4a0) usr.bin/w/w.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)