-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
On Linux/MAC, the 'MINUS SIGN' (U+2212)' symbol is used as NegativeSign when a number is converted to strings and the Swedish culture is applied. See #26778.
This leads to unexpected behavior of the XAttribute class's value property.
If you pass a negative float number as a value of XAttribute, it will be converted to a string with an invariant culture.
(new XAttribute("a", -123f)).Value // will have 'HYPHEN-MINUS' symbol
If you pass a negative integer number as a value of XAttribute, it will be converted to a string with current culture settings. In the case of Linux + Swedish culture, incorrect xml is produced.
(new XAttribute("a", -123)).Value // will have 'MINUS SIGN' symbol
Please see the sample project below.
Steps to reproduce:
- Extract files from dotnetcoredocker.zip to the empty folder.
- Run the docker command:
docker build -t xmlculture . && docker run -it xmlculture
Actual Result:
Integer:
−123
\u2212
Float:
-123
\u002d
the "minus sign" is different for integer and float attribute value types: \u2212(MINUS SIGN) for integer and \u002d(HYPHEN-MINUS) for float.
Expected Result:
the "minus sign" is the same for integer and float attribute value types: \u002d(HYPHEN-MINUS) for integer and \u002d(HYPHEN-MINUS) for float.
I think the issue may be related to this code:
| internal static string GetStringValue(object value) |
For float, double and decimal are converted to a string with an invariant culture, and an integer value is converted with the toString method without parameters.