Bug 37681

Summary: Fails to parse negative integers with Hebrew region set
Product: [Mono] Class Libraries Reporter: Christer Nordvik <cnordvik>
Component: mscorlibAssignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: kumpera, masafa, mono-bugs+monotouch, mono-bugs+mono, pj.beaman, prchol, rolf
Priority: ---    
Version: master   
Target Milestone: (C7)   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

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