-
Notifications
You must be signed in to change notification settings - Fork 366
Default value conversion error if the application locale is set #1160
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
base: main
Are you sure you want to change the base?
Default value conversion error if the application locale is set #1160
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1160 +/- ##
===========================================
Coverage 100.00% 100.00%
===========================================
Files 17 17
Lines 4546 5066 +520
Branches 0 1027 +1027
===========================================
+ Hits 4546 5066 +520 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The other fix option is to force all formatting/parsing operations to be in "C" locale but it may impact the current users of the library who may already use locale-specific parsing. |
I like the solution, I am starting to play with ways to get some tests in place. If I get something working I will try to merge with your branch. |
I made a PR into the branch for this PR, if that is merged then it should clear up some of the missing coverage. There will likely need to be a second test with an unsigned int, and floating point to get the rest. |
… and float conversion
977d16f
to
af1cafb
Compare
Thanks, @phlptp, I added your test case into the PR. BTW, I found that the issue is more complex than I thought. I've hacked
|
af1cafb
to
11c66c9
Compare
Short description
Application fails with
CLI::ConversionError
in some locales if the application locale is set.Root cause
CLI11 uses
std::stringstream
to format default value andstrtol
/strtod
to parse them back. The first method adds locale-specific thousand separators but the second method parses the number only up to the first separator. This causes an exception when the same value is converted to string representation and then parsed back.Examples: in en_US locale 1234.56 is "1,234.56" and in de_DE locale 1234.56 is "1.234,56".
Reproduction
Output:
Fix description
The fix strips group separators from the input string. This extends a bit the logic introduced in change #968 for
_
and'
separators.There are no unit tests for the change because it requires to have all mentioned locales to be installed in the system.