[Mono-bugs] [Bug 52283][Nor] New - String.StartsWith(String.Empty) throws ArgumentOutOfRangeException

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 17 Dec 2003 01:26:20 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by ginga@kit.hi-ho.ne.jp.

http://bugzilla.ximian.com/show_bug.cgi?id=52283

--- shadow/52283	2003-12-17 01:26:20.000000000 -0500
+++ shadow/52283.tmp.10168	2003-12-17 01:26:20.000000000 -0500
@@ -0,0 +1,79 @@
+Bug#: 52283
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: cygwin on WinXP
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: ginga@kit.hi-ho.ne.jp               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: String.StartsWith(String.Empty) throws ArgumentOutOfRangeException
+
+When calling anyString.StartsWith (String.Empty), MS.NET returns true, 
+while mono throws ArgumentOutOfRangeException.
+
+using System;
+public class Test
+{
+        public static void Main ()
+        {
+                Console.WriteLine ("foo".StartsWith ("f"));
+                Console.WriteLine ("foo".StartsWith (""));
+                Console.WriteLine ("".StartsWith ("f"));
+                Console.WriteLine ("".StartsWith (""));
+}
+
+
+Actual Results:
+$ mono path.exe
+True
+
+Unhandled Exception: System.ArgumentOutOfRangeException: Argument is out 
+of range
+Parameter name: Offset2 is greater than or equal to the length of string2
+in <0x00088> System.Globalization.CompareInfo:Compare 
+(string,int,int,string,int,int,System.Globalization.CompareOptions)
+in <0x00187> System.String:Compare 
+(string,int,string,int,int,bool,System.Globalization.CultureInfo)
+in <0x00043> System.String:Compare (string,int,string,int,int)
+in <0x00058> System.String:StartsWith (string)
+in <0x00044> .Test:Main ()
+
+Expected Results:
+$ ./path.exe
+True
+True
+False
+True
+
+How often does this happen? 
+Always
+
+Additional Information:
+
+Here is the proposted patch.
+
+Index: String.cs
+===================================================================
+RCS file: /cvs/public/mcs/class/corlib/System/String.cs,v
+retrieving revision 1.98
+diff -u -r1.98 String.cs
+--- String.cs   6 Dec 2003 16:54:59 -0000       1.98
++++ String.cs   17 Dec 2003 06:13:52 -0000
+@@ -608,6 +608,9 @@
+                                throw new ArgumentNullException("value");
+                        }
+
++                       if (value == String.Empty)
++                               return true;
++
+                        if (this.length < value.length) {
+                                return(false);
+                        }