[Mono-bugs] [Bug 42529][Min] New - Regex.IsMatch throws exception with empty OR in group.
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
Wed, 7 May 2003 15:28:52 -0400 (EDT)
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 tom@acquist.com.
http://bugzilla.ximian.com/show_bug.cgi?id=42529
--- shadow/42529 Wed May 7 15:28:52 2003
+++ shadow/42529.tmp.11233 Wed May 7 15:28:52 2003
@@ -0,0 +1,136 @@
+Bug#: 42529
+Product: Mono/Class Libraries
+Version: unspecified
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Minor
+Component: System
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: tom@acquist.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Regex.IsMatch throws exception with empty OR in group.
+
+Description of Problem:
+Regex.IsMatch will throw a NullReferenceException when the pattern
+contains a an empty member in a group, in the first position of the group,
+when the pattern contains the * quantifier and the end of line specifier.
+Or, to put it simply, Regex.IsMatch("Match something from here.",
+@"(|something|dog)*$") throws an exception. Moving the empty option in
+the group to @"(something||dog)*$" will not throw an exception, and
+neither does moving it to the last position. It is only in the first
+position where this is a problem. Furthermore, if either the * or the $
+is removed, the exception will not be thrown.
+
+
+Steps to reproduce the problem:
+Compile and run the following:
+
+using System;
+using System.Text.RegularExpressions;
+
+public class RegexError2
+{
+
+public static void Main()
+{
+ Console.WriteLine("Only end of line.");
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(something|dog)$"));
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(|something|dog)$"));
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(something||dog)$"));
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(something|dog|)$"));
+
+ Console.WriteLine();
+ Console.WriteLine("Star.");
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(something|dog)*"));
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(|something|dog)*"));
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(something||dog)*"));
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(something|dog|)*"));
+
+ Console.WriteLine();
+ Console.WriteLine("Star and end of line.");
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(something|dog)*$"));
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(|something|dog)*$"));
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(something||dog)*$"));
+ Console.WriteLine(Regex.IsMatch("Match something from here.",
+@"(something|dog|)*$"));
+
+}
+
+}
+
+Actual Results:
+On Mono 0.24, this will run until the second line in the last group, where
+it will throw the following exception:
+
+Unhandled Exception: System.NullReferenceException: A null value was found
+where an object instance was required
+in <0x011ed> 00 System.Text.RegularExpressions.Interpreter:Eval
+(Mode,int&,int)
+in <0x00fd3> 00 System.Text.RegularExpressions.Interpreter:Eval
+(Mode,int&,int)
+in <0x01625> 00 System.Text.RegularExpressions.Interpreter:Eval
+(Mode,int&,int)
+in <0x01196> 00 System.Text.RegularExpressions.Interpreter:Eval
+(Mode,int&,int)
+in <0x00078> 00 System.Text.RegularExpressions.Interpreter:TryMatch
+(int&,int)
+in <0x00733> 00 System.Text.RegularExpressions.Interpreter:Eval
+(Mode,int&,int)
+in <0x0003e> 00 System.Text.RegularExpressions.Interpreter:Scan
+(System.Text.RegularExpressions.Regex,string,int,int)
+in <0x0005b> 00 System.Text.RegularExpressions.Regex:Match (string,int)
+in <0x00017> 00 System.Text.RegularExpressions.Regex:IsMatch (string,int)
+in <0x00019> 00 System.Text.RegularExpressions.Regex:IsMatch (string)
+in <0x00047> 00 System.Text.RegularExpressions.Regex:IsMatch
+(string,string,System.Text.RegularExpressions.RegexOptions)
+in <0x00015> 00 System.Text.RegularExpressions.Regex:IsMatch
+(string,string)
+in <0x00153> 00 .RegexError2:Main ()
+
+Expected Results:
+From .Net 1.1:
+
+Only end of line.
+False
+True
+True
+True
+
+Star.
+True
+True
+True
+True
+
+Star and end of line.
+True
+True
+True
+True
+
+How often does this happen?
+Always.
+
+
+Additional Information:
+
+A simple workaround for at least this manifestation of the bug (I get the
+feeling it'll show up elsewhere in other obscure places...) is to move the
+empty option out of the first position in the group.