[Mono-dev] Patch for DateTime.TryParseExact handling of null input string

Miguel de Icaza miguel at novell.com
Mon Mar 1 11:50:34 EST 2010


Hello!

   Thanks for the patch.

> .NET 3.5 does not throw a null reference exception on DateTime.TryParseExact if the first parameter is null.
> 
> Attached is a test case and a fix for DateTime.cs
> 
> Index: System/DateTime.cs
> ===================================================================
> --- System/DateTime.cs	(revision 152377)
> +++ System/DateTime.cs	(working copy)
> @@ -1164,6 +1164,9 @@
>  			result = new DateTime (0);
>  			if (format == null)
>  				return false;
> +			
> +			if (s == null)
> +				return false;
>  
>  			if ((style & DateTimeStyles.AllowLeadingWhite) != 0) {
>  				format = format.TrimStart (null);
> Index: Test/System/DateTimeTest.cs
> ===================================================================
> --- Test/System/DateTimeTest.cs	(revision 152377)
> +++ Test/System/DateTimeTest.cs	(working copy)
> @@ -2417,6 +2417,15 @@
>  			// bug #444103.
>  			DateTime.ParseExact ("12:00:00", "HH:mm:ss.FFFFFFF", null);
>  		}
> +		
> +		[Test]
> +		public void TryParseExact_NullString ()
> +		{
> +			DateTime dt;
> +			DateTime.TryParseExact(null, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture,
> +							DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out dt);
> +			Assert.AreEqual(default(DateTime), dt);
> +		}
>  #endif
>  	}
>  }
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list




More information about the Mono-devel-list mailing list