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)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

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.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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