Bug 10670 fix.
[mono.git] / mcs / class / System / System.Text.RegularExpressions / parser.cs
index 84042cd1153208300ed412632626a40bf9bef16f..f3ddf196730bb8879cbdc0dd8fc5a82829c91486 100644 (file)
@@ -149,24 +149,25 @@ namespace System.Text.RegularExpressions.Syntax {
                        }
                }
 
-               public IDictionary GetMapping () {
+               public IDictionary GetMapping ()
+               {
                        Hashtable mapping = new Hashtable ();
-                       Hashtable numbers = new Hashtable ();
                        int end = caps.Count;
                        mapping.Add ("0", 0);
                        for (int i = 0; i < end; i++) {
                                CapturingGroup group = (CapturingGroup) caps [i];
-                               if (group.Name != null && !mapping.Contains (group.Name)) {
+                               if (group.Name != null) {
+                                       if (mapping.Contains (group.Name)) {
+                                               if ((int) mapping [group.Name] != group.Number)
+                                                       throw new SystemException ("invalid state");
+                                               continue;
+                                       }
                                        mapping.Add (group.Name, group.Number);
-                                       numbers.Add (group.Number, group.Number);
+                               } else {
+                                       mapping.Add (group.Number.ToString (), group.Number);
                                }
                        }
 
-                       for (int i = 1; i < end; i++) {
-                               if (numbers [i] == null)
-                                       mapping.Add (i.ToString (), i);
-                       }
-
                        return mapping;
                }
 
@@ -528,7 +529,7 @@ namespace System.Text.RegularExpressions.Syntax {
                                }
                                else {                                          // capture test
                                        ++ ptr;
-                                       asn = new CaptureAssertion ();
+                                       asn = new CaptureAssertion (new Literal (name, IsIgnoreCase (options)));
                                        refs.Add (asn, name);
                                }
 
@@ -760,8 +761,8 @@ namespace System.Text.RegularExpressions.Syntax {
 
                        /* check bounds and ordering */
 
-                       if (n >= 0xffff || m >= 0xffff)
-                               throw NewParseException ("Illegal {x, y} - maximum of 65535.");
+                       if (n > 0x7fffffff || m > 0x7fffffff)
+                               throw NewParseException ("Illegal {x, y} - maximum of 2147483647.");
                        if (m >= 0 && m < n)
                                throw NewParseException ("Illegal {x, y} with x > y.");
 
@@ -771,7 +772,7 @@ namespace System.Text.RegularExpressions.Syntax {
                        if (m > 0)
                                max = m;
                        else
-                               max = 0xffff;
+                               max = 0x7fffffff;
 
                        return true;
                }
@@ -1096,6 +1097,8 @@ namespace System.Text.RegularExpressions.Syntax {
                        foreach (Expression expr in refs.Keys) {
                                string name = (string)refs[expr];
                                if (!dict.Contains (name)) {
+                                       if (expr is CaptureAssertion && !Char.IsDigit (name [0]))
+                                               continue;
                                        throw NewParseException ("Reference to undefined group " +
                                                (Char.IsDigit (name[0]) ? "number " : "name ") +
                                                name);