[Mono-bugs] [Bug 41678][Min] New - Regex.Replace should not fully compile replacement.

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Mon, 21 Apr 2003 17:43:42 -0400 (EDT)


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 tom@acquist.com.

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

--- shadow/41678	Mon Apr 21 17:43:42 2003
+++ shadow/41678.tmp.406	Mon Apr 21 17:43:42 2003
@@ -0,0 +1,81 @@
+Bug#: 41678
+Product: Mono/Class Libraries
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Minor
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: tom@acquist.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Regex.Replace should not fully compile replacement.
+
+Description of Problem:
+Regex.Replace will compile the replacement, so replacements with 
+characters or sequences that have special meanings in ordinary regular 
+expressions will have problems with Regex.Replace.  It should only 
+translate the $ group references (${name}, $1, $+, etc.), but leave the 
+rest of the replacement as-is.  In particular, right now, any replacement 
+with a backslash in it will have the backslash treated as part of an 
+escape sequence, which it should not be.
+
+
+Steps to reproduce the problem:
+Compile and run the following:
+
+using System;
+using System.Text.RegularExpressions;
+
+public class RegexError
+{
+
+public static void Main()
+{
+   Console.WriteLine(Regex.Replace(@"/dev/null", @"/", @"\\"));
+   Console.WriteLine(Regex.Replace(@"/dev/null", @"/", @"\"));
+}
+
+}
+
+Actual Results:
+It prints (In Mono 0.23):
+
+\dev\null
+
+Unhandled Exception: System.ArgumentException: Parsing "\" - Illegal \ at 
+end of pattern.
+Parameter name: \
+in <0x00069> 00 System.Text.RegularExpressions.Syntax.Parser:ParseEscape ()
+in <0x00080> 00 System.Text.RegularExpressions.Syntax.Parser:ParseString 
+(string)
+in <0x00044> 00 
+System.Text.RegularExpressions.ReplacementEvaluator:Compile (string)
+in <0x0005b> 00 System.Text.RegularExpressions.ReplacementEvaluator:.ctor 
+(System.Text.RegularExpressions.Regex,string)
+in <0x00032> 00 System.Text.RegularExpressions.Regex:Replace 
+(string,string,int,int)
+in <0x00052> 00 System.Text.RegularExpressions.Regex:Replace 
+(string,string,string,System.Text.RegularExpressions.RegexOptions)
+in <0x00068> 00 .RegexError:Main ()
+
+
+Expected Results:
+It should print (And does in .Net):
+
+\\dev\\null
+\dev\null
+
+
+How often does this happen?
+Always.
+
+
+Additional Information:
+That exception also seems a little odd, with "\" being listed as the 
+parameter name, but that's just a minor cosmetic issue.