Description
Bug
If the machine's locale is set to a language like German (de) or French (fr), rendering SVG paths that contain floating point numbers will crash if the floating point numbers use dots instead of commas as the radix. This is because languages like German expect the usage of commas in floating-point numbers (i.e. ",482" instead of ".482"), and std::stof
takes into account the current locale of the application. PathView utilizes std::stof
in its parsing logic.
Fix recommendation: std::from_chars
should be used instead as it will always use the C-default locale instead of whatever is currently set in the application. I have tested this locally and this seems to work as expected.
Environment info
As far as I know, this reproduces on Windows 11 environments in react-native-svg version 13.14.0, and the latest 14.1.0.
Steps To Reproduce
Issues without reproduction steps or code are likely to stall.
- Clone/build react-native-svg as normal for Windows environment.
- Force the locale to be German in C++ at the start of
PathView::UpdateProperties
viastd::setlocale(LC_ALL, "de_DE");
. - Create a simple SVG path component with the following value for its
d
property:"m41.213 20.483 6.8889 3.1408m0.48227-3.8605-7.3712 0.71964 7.2985 1.2256"
- Build and run. Try to display SVG path from part 3.
- Observe that the program crashes due to invalid argument exception in
PathView::ParseNumber
during thestd::stof
call.
Describe what you expected to happen:
- Any SVG should render on Windows using German (de) locale and not crash. Specifically, SVGs using paths with floating-point values that use decimals for the radix instead of commas.
Short, Self Contained, Correct (Compilable), Example
N/A
If more information is needed, please let me know.