[Mono.Debugger.Soft] Escape some unicode characters in literal strings
authorJeffrey Stedfast <jeff@xamarin.com>
Tue, 18 Sep 2012 22:06:55 +0000 (18:06 -0400)
committerJeffrey Stedfast <jeff@xamarin.com>
Tue, 18 Sep 2012 22:06:55 +0000 (18:06 -0400)
Fix for bug #6369

mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/MethodBodyMirror.cs

index c383005a0d41979d8d92977b7f96d93c4b7091f3..61af2c0c49c8bc064d0465206b118252ed77b01b 100644 (file)
@@ -56,8 +56,38 @@ namespace Mono.Debugger.Soft
                static OpCode [] OneByteOpCode = new OpCode [0xe0 + 1];
                static OpCode [] TwoBytesOpCode = new OpCode [0x1e + 1];
 
+               static string EscapeString (string text)
+               {
+                       StringBuilder sb = new StringBuilder ();
+                       for (int i = 0; i < text.Length; i++) {
+                               char c = text[i];
+                               string txt;
+                               switch (c) {
+                               case '"': txt = "\\\""; break;
+                               case '\0': txt = @"\0"; break;
+                               case '\\': txt = @"\\"; break;
+                               case '\a': txt = @"\a"; break;
+                               case '\b': txt = @"\b"; break;
+                               case '\f': txt = @"\f"; break;
+                               case '\v': txt = @"\v"; break;
+                               case '\n': txt = @"\n"; break;
+                               case '\r': txt = @"\r"; break;
+                               case '\t': txt = @"\t"; break;
+                               default:
+                                       if (char.GetUnicodeCategory (c) == UnicodeCategory.OtherNotAssigned) {
+                                               sb.AppendFormat ("\\u{0:x4}", (int) c);
+                                       } else {
+                                               sb.Append (c);
+                                       }
+                                       continue;
+                               }
+                               sb.Append (txt);
+                       }
+                       return sb.ToString ();
+               }
+
                // Adapted from Cecil
-           List<ILInstruction> ReadCilBody (BinaryReader br, int code_size)
+               List<ILInstruction> ReadCilBody (BinaryReader br, int code_size)
                {
                        long start = br.BaseStream.Position;
                        ILInstruction last = null;
@@ -153,7 +183,7 @@ namespace Mono.Debugger.Soft
                                        token = br.ReadInt32 ();
                                        t = vm.conn.Method_ResolveToken (Method.Id, token);
                                        if (t.Type == TokenType.STRING)
-                                               instr.Operand = t.Str;
+                                               instr.Operand = EscapeString (t.Str);
                                        break;
                                case OperandType.InlineField :
                                case OperandType.InlineMethod :