Author: raja
Date: 2005-06-14 07:44:35 -0400 (Tue, 14 Jun 2005)
New Revision: 45958

Modified:
   trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
   trunk/mcs/class/System/System.Text.RegularExpressions/GroupCollection.cs
   trunk/mcs/class/System/System.Text.RegularExpressions/Match.cs
   trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
   trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexBugs.cs
Log:
In System.Text.RegularExpressions:
        Fix #74753.
        * Match.cs (Match) [zero-argument variant]: Make private.
        * GroupCollection (Item) [string variant]: Don't look for the
        group number in an empty match.

In Test/System.Text.RegularExpressions:
        * RegexBugs.cs (NameLookupInEmptyMatch): New test from #74753.


Modified: trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog     
2005-06-14 11:33:36 UTC (rev 45957)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog     
2005-06-14 11:44:35 UTC (rev 45958)
@@ -1,3 +1,10 @@
+2005-06-14  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       Fix #74753.
+       * Match.cs (Match) [zero-argument variant]: Make private.
+       * GroupCollection (Item) [string variant]: Don't look for the
+       group number in an empty match.
+
 2005-06-10  Raja R Harinath  <[EMAIL PROTECTED]>
 
        * interpreter.cs (Interpreter.GenerateMatch): Avoid allocating two

Modified: 
trunk/mcs/class/System/System.Text.RegularExpressions/GroupCollection.cs
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/GroupCollection.cs    
2005-06-14 11:33:36 UTC (rev 45957)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/GroupCollection.cs    
2005-06-14 11:44:35 UTC (rev 45958)
@@ -74,11 +74,10 @@
 
                public Group this [string groupName] {
                        get {
-                               foreach (Group g in list) {
-                                       if (!(g is Match))
-                                               continue;
-
-                                       int index = 
((Match)g).Regex.GroupNumberFromName (groupName);
+                               // The 0th group is the match.
+                               Match m = (Match) list [0];
+                               if (m != Match.Empty) {
+                                       int index = m.Regex.GroupNumberFromName 
(groupName);
                                        if (index != -1)
                                                return this [index];
                                }

Modified: trunk/mcs/class/System/System.Text.RegularExpressions/Match.cs
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/Match.cs      
2005-06-14 11:33:36 UTC (rev 45957)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/Match.cs      
2005-06-14 11:44:35 UTC (rev 45958)
@@ -68,7 +68,7 @@
 
                // internal
 
-               internal Match () : base ()
+               private Match () : base ()
                {
                        this.regex = null;
                        this.machine = null;

Modified: trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog        
2005-06-14 11:33:36 UTC (rev 45957)
+++ trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog        
2005-06-14 11:44:35 UTC (rev 45958)
@@ -1,3 +1,7 @@
+2005-06-14  Raja R Harinath  <[EMAIL PROTECTED]>
+
+       * RegexBugs.cs (NameLookupInEmptyMatch): New test from #74753.
+
 2005-05-25  Raja R Harinath  <[EMAIL PROTECTED]>
 
        * RegexReplace.cs: Add a couple more testcases.

Modified: 
trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexBugs.cs
===================================================================
--- trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexBugs.cs     
2005-06-14 11:33:36 UTC (rev 45957)
+++ trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexBugs.cs     
2005-06-14 11:44:35 UTC (rev 45958)
@@ -147,7 +147,7 @@
                        rex += 
"type\\s*=\\s*[\"']?text/xml[\"']?\\s*href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^']*)'|(?<1>\\S+))";
                        Regex rob = new Regex (rex, RegexOptions.IgnoreCase);
                }
-               
+
                [Test]
                public void UndefinedGroup () // bug 52890
                {
@@ -277,6 +277,25 @@
                        x = new Regex ("{a}");
                        x = new Regex ("{,a}");
                }
+
+               [Test]
+               public void NameLookupInEmptyMatch () // bug 74753
+               {
+                       Regex regTime = new Regex (
+                                       
@"(?<hour>[0-9]{1,2})([\:](?<minute>[0-9]{1,2})){0,1}([\:](?<second>[0-9]{1,2})){0,1}\s*(?<ampm>(?i:(am|pm)){0,1})");
+
+                       Match mTime = regTime.Match("");
+                       AssertEquals ("#01", "", mTime.Groups["hour"].Value);
+                       AssertEquals ("#02", "", mTime.Groups["minute"].Value);
+                       AssertEquals ("#03", "", mTime.Groups["second"].Value);
+                       AssertEquals ("#04", "", mTime.Groups["ampm"].Value);
+
+                       mTime = regTime.Match("12:00 pm");
+                       AssertEquals ("#05", "12", mTime.Groups["hour"].Value);
+                       AssertEquals ("#06", "00", 
mTime.Groups["minute"].Value);
+                       AssertEquals ("#07", "", mTime.Groups["second"].Value);
+                       AssertEquals ("#08", "pm", mTime.Groups["ampm"].Value);
+               }
        }
 }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to