Bug 4396 - int.Parse succeeds when it should fail with AllowExponent specified
Summary: int.Parse succeeds when it should fail with AllowExponent specified
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 2.10.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-04-11 14:18 UTC by Martin Potter
Modified: 2012-04-13 04:13 UTC (History)
2 users (show)

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:

Description Martin Potter 2012-04-11 14:18:09 UTC
It appears the exponent parsing in Int32.FindExponent is too naïve/aggressive about the detection/parsing of possible exponents. The following example should throw a FormatException, but outputs "20" instead:

System.Console.Error.WriteLine(int.Parse("2 math's hard, lεt's go shopping e1", System.Globalization.NumberStyles.AllowExponent));

On master this occurs for both int.Parse and long.Parse; on 2.10.x the error only occurs for int.Parse, as it appears that exponent parsing for Int64 was added to master to fix bug #2516.
Comment 1 Marek Safar 2012-04-12 10:48:47 UTC
Fixed in master.
Comment 2 Martin Potter 2012-04-12 15:05:05 UTC
I commented on GitHub, but figured I should add it to the case as well. The condition on line 282 of Int32.cs should include a check for pos >= s.Length, as int.Parse now throws an IndexOutOfRangeException for int.Parse("1", System.Globalization.NumberStyles.Any).
Comment 3 Marek Safar 2012-04-13 04:13:42 UTC
Good point. Fixed.