Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curl respects the locale's number format setting for parsing fractional seconds, it does not enforce dot #9969

Closed
danielfaust opened this issue Nov 23, 2022 · 10 comments

Comments

@danielfaust
Copy link

danielfaust commented Nov 23, 2022

I did this

In bash and zsh: curl --connect-timeout 3.14 https://example.com

I expected the following

The following printed out to stdout:

<!doctype html>
<html>
<head>
    <title>Example Domain</title>

...

</html>

The actual result was

curl: option --connect-timeout: expected a proper numerical parameter

curl/libcurl version

curl 7.81.0 (x86_64-pc-linux-gnu) libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 brotli/1.0.9 zstd/1.4.8 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.2) libssh/0.9.6/openssl/zlib nghttp2/1.43.0 librtmp/2.3 OpenLDAP/2.5.13
Release-Date: 2022-01-05

as well as

curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
Release-Date: 2020-01-08

operating system

Ubuntu 22.04 LTS
Linux hostname 5.15.0-53-generic #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

With LC_NUMERIC="de_DE.UTF-8"

as well as

Ubuntu 20.04 LTS
Linux hostname 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

With LC_NUMERIC="de_DE.UTF-8"

workaround

Add export LC_NUMERIC="en_US.UTF-8" to environments requiring fractional seconds in the timeouts.

@bagder
Copy link
Member

bagder commented Nov 23, 2022

Doesn't your command line and claim contradict each other? German uses comma and not a period ? (like Swedish btw)

curl uses the dot-version (it ignores the locale) fixed and on purpose so that command lines become transferable between systems. This is intentional. The documentation could probably make that clearer.

bagder added a commit that referenced this issue Nov 23, 2022
Independently of what the locale says

Reported-by: Daniel Faust
Ref: #9969
@danielfaust
Copy link
Author

danielfaust commented Nov 23, 2022

I recognize my mistake and I was about to close this issue, but then I re-read your answer and there's also something wrong:

curl uses the dot-version (as it ignoring the locale) fixed and on purpose so that command lines become transferable between systems. This is intentional.

Consider the following command line "dialogue":

~ export LC_NUMERIC="de_DE.UTF-8"
~ locale -k decimal_point
decimal_point="," 
~ curl --connect-timeout 3.14 https://example.com
curl: option --connect-timeout: expected a proper numerical parameter
curl: try 'curl --help' or 'curl --manual' for more information
~ curl --connect-timeout 3,14 https://example.com
<!doctype html>
<html>
...
</html>
~ export LC_NUMERIC="en_US.UTF-8"
~ curl --connect-timeout 3,14 https://example.com
curl: option --connect-timeout: expected a proper numerical parameter
curl: try 'curl --help' or 'curl --manual' for more information

Exactly like you I had the feeling that using a dot would be the proper way to do it, but it actually is the contrary of what the title of this issue says:

So instead of

Curl does not respect the locale's number format setting for parsing fractional seconds.

it should be

Curl applies the locale's number format setting when parsing fractional seconds.

This entire thing is pretty confusing to me, since I also would expect to use a dot on the command line for decimals in the parameters, but also respecting the locale isn't technically that wrong neiter.

I'm managing 10+ servers which all have use LC_NUMERIC="en_US.UTF-8" and two Linux desktops which have LC_NUMERIC="de_DE.UTF-8" and there I was seeing this issue when using a script which I created on a server.


Update: Sorry for being late with this reply to your answer. You submitted the PR on the docs while I was typing this answer, so I didn't see it. Apparently this now makes the docs be officially in contradiction with what curl is actually doing.

@bagder
Copy link
Member

bagder commented Nov 23, 2022

Apparently this now makes the docs be officially in contradiction with what curl is actually doing.

The fact that you said the complete opposite in the title is highly confusing...

@bagder bagder changed the title Curl does not respect the locale's number format setting for parsing fractional seconds. curl respects the locale's number format setting for parsing fractional seconds, it does not enforce dot Nov 23, 2022
@bagder
Copy link
Member

bagder commented Nov 23, 2022

Using 7.86.0 or 7.87.0-DEV on my Linux:

LC_NUMERIC="de_DE.UTF-8" ./src/curl -m 3,14 localhost
curl: option -m: expected a proper numerical parameter
curl: try 'curl --help' or 'curl --manual' for more information

@bagder
Copy link
Member

bagder commented Nov 23, 2022

How do you build/get your curl?

@bagder
Copy link
Member

bagder commented Nov 23, 2022

Plain ubuntu install?

@danielfaust
Copy link
Author

danielfaust commented Nov 23, 2022

It's on Kubuntu 20.04 LTS and Kubuntu 22.04 LTS.

It's the version from the repository, I don't know it it was pre-installed or if I manually used apt install.

Opening this issue was a result of this Stack Exchange post I made: https://unix.stackexchange.com/questions/725973/curl-option-connect-timeout-expected-a-proper-numerical-parameter

The versions are

curl 7.81.0 (x86_64-pc-linux-gnu) libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 brotli/1.0.9 zstd/1.4.8 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.2) libssh/0.9.6/openssl/zlib nghttp2/1.43.0 librtmp/2.3 OpenLDAP/2.5.13
Release-Date: 2022-01-05

and

curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
Release-Date: 2020-01-08

@bagder
Copy link
Member

bagder commented Nov 23, 2022

I can also reproduce on ubuntu 20.04, both with the shipped version and my own build. Clearly the setlocale() call has no effect... ?

@bagder
Copy link
Member

bagder commented Nov 23, 2022

If locale is an empty string, "", each part of the locale that should be modified is set according to the environment variables

It turns out we should set it to "C" if we want to override it...

@danielfaust
Copy link
Author

Thank you for your work.

bagder added a commit that referenced this issue Nov 24, 2022
Independently of what the locale says

Reported-by: Daniel Faust
Ref: #9969
bagder added a commit that referenced this issue Nov 24, 2022
@bagder bagder closed this as completed in 975efec Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants