Bug 37681 - Fails to parse negative integers with Hebrew region set
Summary: Fails to parse negative integers with Hebrew region set
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: (C7)
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-01-14 08:47 UTC by Christer Nordvik
Modified: 2016-03-02 16:48 UTC (History)
7 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Christer Nordvik 2016-01-14 08:47:39 UTC
Is this a bug or intended behavior? I know I can set the culture info when parsing but our app is live (and crashing) so just need to know if I have to change everywhere we parse a string into an int... 

Running app in Simulator

Hebrew language
>int.Parse("-1")
System.FormatException: Input string was not in a correct format.
>int.Parse("1")
1

English language
>int.Parse("-1")
-1
>int.Parse("1")
1
Comment 2 Rolf Bjarne Kvinge [MSFT] 2016-01-14 09:18:34 UTC
The following test case:

	try {
		var he = CultureInfo.GetCultureInfo ("he-IL");
		var ns = he.NumberFormat.NegativeSign;
		Console.WriteLine ("{0} negative sign: {1} length: {2}", he.Name, ns, ns.Length);
		for (int i = 0; i < ns.Length; i++)
			Console.WriteLine ("    Character #{0}: 0x{1}", i + 1, ((int) ns [i]).ToString ("x"));
		ns = "-";
		Console.WriteLine ("English negative sign: {1} length: {2}", "?", ns, ns.Length);
		for (int i = 0; i < ns.Length; i++)
			Console.WriteLine ("    Character #{0}: 0x{1}", i + 1, ((int) ns [i]).ToString ("x"));
		Console.WriteLine (int.Parse (he.NumberFormat.NegativeSign + "1", he));
		Console.WriteLine (int.Parse ("-1", he));
	} catch (Exception e) {
		Console.WriteLine (e.Message);
	}

prints this in Xamarin.iOS (or Mono 4.2.1 for that matter):

	he-IL negative sign: ‎- length: 2
	    Character #1: 0x200e
	    Character #2: 0x2d
	English negative sign: - length: 1
	    Character #1: 0x2d
	-1
	Input string was not in a correct format.

and this on Windows (VS2010):

	he-IL negative sign: - length: 1
	    Character #1: 0x2d
	English negative sign: - length: 1
	    Character #1: 0x2d
	-1
	-1

so it looks like the difference is that in Xamarin.iOS the NumberFormat.NegativeSign property contains 0x200e (LEFT-TO-RIGHT-MARK [1]), while .NET does not.

[1] http://www.fileformat.info/info/unicode/char/200e/index.htm
Comment 3 Marek Safar 2016-01-14 14:15:44 UTC
Fixed in mono master
Comment 4 Rolf Bjarne Kvinge [MSFT] 2016-01-18 10:03:37 UTC
@Marek, is this something that can go in a SR (i.e. mono-4.2.x-branch)?
Comment 5 Marek Safar 2016-01-18 11:14:04 UTC
It can go to 4.2 if needed
Comment 7 Rolf Bjarne Kvinge [MSFT] 2016-01-18 12:02:08 UTC
This was the fix: https://github.com/mono/mono/commit/4cf5ddee6d69be829038ee545192f40968167ef9

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Note You need to log in before you can comment on or make changes to this bug.