[Mono-bugs] [Bug 529206] New: More behaviour differences between .NET and Mono versions of System.Text.RegularExpressions.Regex class.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Aug 7 09:46:21 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=529206


           Summary: More behaviour differences between .NET and Mono
                    versions of System.Text.RegularExpressions.Regex
                    class.
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.0.x
          Platform: x86-64
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: jimteeuwen at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.13)
Gecko/2009080315 Ubuntu/9.04 (jaunty) Firefox/3.0.13

The bug list already has a number of entries related to the Regex class not
behaving as it should, but I have not encountered an entry detailing the
inconsistent behaviour of it's Replace() method. So here goes..

It appears that Mono's Regex.Replace(input, pattern, replacement) method only
replaces a number of characters equal to the length of the matched string,
while it should completely replace <match> with <replacement>, regardless of
either string's length.

For example:
[code]
using System;
using System.Text.RegularExpressions;

namespace Test
{
    static class Entry
    {
        static void Main(string[] args)
        {
            string mystr = "cookies rock and stuff";

            // This should replace each /single/ whitespace character with
'___'
            mystr = Regex.Replace(mystr, @"\s", "___");

            Console.WriteLine(mystr);
            Console.Read();
        }
    }
}
[/code]

The above code should replace each occurrence of a whitespace character with
'___'. This means that the resulting string after the replacement is larger in
length than the original input string. This works as expected in .NET, but Mono
seems to want to retain the input string's original size and thus only replaces
a number of characters equal to the length of the match that was found.

In the above example, each match will only consist of a single space ' '. 
The replacement will therefor only be done on a single character, and thus
change ' ' into '_'. This is incorrect behaviour.

Reproducible: Always

Steps to Reproduce:
1. Paste the code listed above in a new sourcefile named 'regextest.cs'
2. compile with: csc regextest.cs /out=regextest.exe
3. Run with: ./regextest.exe

Actual Results:  
cookes_rock_and_stuff

Expected Results:  
cookes___rock___and___stuff

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list