Fix 324390
authorRaja R Harinath <harinath@hurrynot.org>
Thu, 8 Nov 2007 03:31:44 +0000 (03:31 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Thu, 8 Nov 2007 03:31:44 +0000 (03:31 -0000)
In System/System.Text.RegularExpressions:
* BaseMachine.cs (LTRReplace): Don't use non-advancement of 'ptr'
to deduce absence of matches -- a match can have length 0.
(RTLReplace): Likewise.

In System/Test/System.Text.RegularExpressions:
* RegexReplace.cs (tests): New test from #324390.

svn path=/trunk/mcs/; revision=89176

mcs/class/System/System.Text.RegularExpressions/BaseMachine.cs
mcs/class/System/System.Text.RegularExpressions/ChangeLog
mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
mcs/class/System/Test/System.Text.RegularExpressions/RegexReplace.cs

index 934cffe756ae9f155d6b556a027e36d5dffe65bd..0d8e06419c03f6f16d64c4dc3f2692a8a8ee7214 100644 (file)
@@ -102,14 +102,17 @@ namespace System.Text.RegularExpressions
 
                internal static string LTRReplace (Regex regex, string input, MatchAppendEvaluator evaluator, int count, int startat)
                {
+                       Match m = regex.Match (input, startat);
+                       if (!m.Success)
+                               return input;
+
                        StringBuilder result = new StringBuilder ();
                        int ptr = startat;
                        int counter = count;
 
                        result.Append (input, 0, ptr);
 
-                       Match m = regex.Match (input, startat);
-                       while (m.Success) {
+                       do {
                                if (count != -1)
                                        if (counter-- <= 0)
                                                break;
@@ -120,10 +123,7 @@ namespace System.Text.RegularExpressions
 
                                ptr = m.Index + m.Length;
                                m = m.NextMatch ();
-                       }
-
-                       if (ptr == startat)
-                               return input;
+                       } while (m.Success);
 
                        result.Append (input, ptr, input.Length - ptr);
 
@@ -132,14 +132,16 @@ namespace System.Text.RegularExpressions
 
                internal static string RTLReplace (Regex regex, string input, MatchEvaluator evaluator, int count, int startat)
                {
+                       Match m = regex.Match (input, startat);
+                       if (!m.Success)
+                               return input;
+
                        int ptr = startat;
                        int counter = count;
-
                        StringCollection pieces = new StringCollection ();
                        pieces.Add (input.Substring (ptr));
 
-                       Match m = regex.Match (input, startat);
-                       while (m.Success) {
+                       do {
                                if (count != -1)
                                        if (counter-- <= 0)
                                                break;
@@ -150,10 +152,7 @@ namespace System.Text.RegularExpressions
 
                                ptr = m.Index;
                                m = m.NextMatch ();
-                       }
-
-                       if (ptr == startat)
-                               return input;
+                       } while (m.Success);
 
                        StringBuilder result = new StringBuilder ();
 
index 4fce74f9f5bbe05f1a1946cb81a7b364012182a5..5c883ba23340fe7365d8f6d4d8bc0fc3392717cc 100644 (file)
@@ -1,3 +1,10 @@
+2007-11-08  Raja R Harinath  <harinath@gmail.com>
+
+       Fix 324390
+       * BaseMachine.cs (LTRReplace): Don't use non-advancement of 'ptr'
+       to deduce absence of matches -- a match can have length 0.
+       (RTLReplace): Likewise.
+
 2007-11-07  Raja R Harinath  <harinath@gmail.com>
 
        Support RegexOptions.RightToLeft in Replace().
index 72ce49d98b3831a8e1ac17031d4429124ee30d52..29fa33c26fe45ad810390f2ed288cd36cda08568 100644 (file)
@@ -1,3 +1,7 @@
+2007-11-08  Raja R Harinath  <harinath@gmail.com>
+
+       * RegexReplace.cs (tests): New test from #324390.
+
 2007-11-07  Raja R Harinath  <harinath@gmail.com>
 
        * MatchTest.cs (Match_Backref): New.
index 9b8d3800368024ce77ed66acb515cb9af558bcdb..d74c21c835ee4c7c246fc6b7bd2a64d3899f6bb4 100644 (file)
@@ -85,7 +85,8 @@ namespace MonoTests.System.Text.RegularExpressions {
                        //new testcase ("F2345678910L71",       @"(F)(2)(3)(4)(5)(6)(?<S>7)(8)(9)(10)(L)\11",   "${S}$11$1", "77F1"     ),
                        new testcase ("F2345678910L71", @"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11",       "${S}$11$1", "F2345678910L71"   ),
                        new testcase ("F2345678910LL1", @"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11",       "${S}$11$1", "${S}LF1", /*FIXME: this should work in RTL direction too */ direction.LTR),
-                       new testcase ("a", "a", @"\\", @"\\"),
+                       new testcase ("a", "a", @"\\", @"\\"), // bug #317092
+                       new testcase ("a", "^", "x", "xa"), // bug #324390
                };
 
                [Test]