[Mono-bugs] [Bug 74088][Wis] New - Regex.Replace barfs on dollar sign-number replacement string

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 24 Mar 2005 21:33:49 -0500 (EST)


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 allan@imeem.com.

http://bugzilla.ximian.com/show_bug.cgi?id=74088

--- shadow/74088	2005-03-24 21:33:49.000000000 -0500
+++ shadow/74088.tmp.23869	2005-03-24 21:33:49.000000000 -0500
@@ -0,0 +1,72 @@
+Bug#: 74088
+Product: Mono: Class Libraries
+Version: 1.1
+OS: other
+OS Details: Fedora Core 2
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: allan@imeem.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Regex.Replace barfs on dollar sign-number replacement string
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+Calling Regex.Replace with a replacement string that contains a '$'
+followed by a numerical digit in it will result in an exception or
+incorrect output. It looks like mono thinks that the replacement string
+refers to a group number, despite the lack of braces around the dollar sign.
+
+The following trivial program will demonstrate:
+
+using System;
+using System.Text.RegularExpressions;
+
+namespace ReplaceBug
+{
+	class ReplaceDemo
+	{
+		[STAThread]
+		static void Main(string[] args)
+		{
+			string blah = Regex.Replace("blah blah blah match", "match", "$1
+crazyness");
+
+			System.Console.WriteLine(blah);
+		}
+	}
+}
+Actual Results:
+On mono 1.1.4, this produces the following exception:
+Unhandled Exception: System.ArgumentException: Bad group number.
+in <0x002b2>
+System.Text.RegularExpressions.ReplacementEvaluator:CompileTerm (string,int&)
+in <0x000b5> System.Text.RegularExpressions.ReplacementEvaluator:Compile
+(string)
+in <0x00043> System.Text.RegularExpressions.ReplacementEvaluator:.ctor
+(System.Text.RegularExpressions.Regex,string)
+in <0x00028> System.Text.RegularExpressions.Regex:Replace
+(string,string,int,int)
+in <0x0004c> System.Text.RegularExpressions.Regex:Replace (string,string)
+in <0x00038> System.Text.RegularExpressions.Regex:Replace
+(string,string,string,System.Text.RegularExpressions.RegexOptions)
+in <0x00012> System.Text.RegularExpressions.Regex:Replace
+(string,string,string)
+in <0x00019> ReplaceBug.ReplaceDemo:Main (string[])
+
+Expected Results:
+Under Windows, the above program outputs:
+"blah blah blah $1 crazyness"
+and then exits.
+
+How often does this happen? 
+Every. single. time.
+
+Additional Information: