diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2022-05-16 00:25:43 +0200 |
---|---|---|
committer | PulseAudio Marge Bot <pulseaudio-maintainers@lists.freedesktop.org> | 2022-05-16 18:15:47 +0000 |
commit | c3c84a3691e700157ccd3c75fdae53c6eec89775 (patch) | |
tree | 16910723562daf012d3d9a043242043a6c906dcb | |
parent | 4f2c8ec002e937ab53bd016c041154bdcc49f217 (diff) | |
download | pulseaudio-c3c84a3691e700157ccd3c75fdae53c6eec89775.tar.gz |
pactl: fix invalid JSON output by overriding LC_NUMERIC
When the --format json parameter is given on the command line, we
attempt to produce a JSON output for most commands.
Our implementation of the JSON serialization uses vsnprintf to output
numbers. Unfortunately, vsnprintf is affected by the locale and more
specifically the LC_NUMERIC variable.
When LC_NUMERIC is set to, for instance, fr_FR.UTF-8, floating-point
numbers are output with a comma as the decimal separator, which is then
considered invalid JSON.
$ LC_NUMERIC=fr_FR.UTF-8 pactl --format json list sinks | jq .
parse error: Objects must consist of key:value pairs at line 1, column 435
This is the token which failed to parse:
}},"balance":0,00,"base_volume":{
Fixed by overriding the LC_NUMERIC value when we request JSON output.
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/702>
-rw-r--r-- | src/utils/pactl.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/utils/pactl.c b/src/utils/pactl.c index 3c1eeb0d0..35163f277 100644 --- a/src/utils/pactl.c +++ b/src/utils/pactl.c @@ -2746,6 +2746,7 @@ int main(int argc, char *argv[]) { format = TEXT; } else if (pa_streq(opt_format, "json")) { format = JSON; + setlocale(LC_NUMERIC, "C"); } else { pa_log(_("Invalid format value '%s'"), opt_format); goto quit; |