]> git.lizzy.rs Git - rust.git/commitdiff
std: Fix demangling with middle special chars
authorAlex Crichton <alex@alexcrichton.com>
Sat, 19 Apr 2014 00:33:47 +0000 (17:33 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sat, 19 Apr 2014 00:37:27 +0000 (17:37 -0700)
Previously, symbols with rust escape sequences (denoted with dollar signs)
weren't demangled if the escape sequence showed up in the middle. This alters
the printing loop to look through the entire string for dollar characters.

src/libstd/rt/backtrace.rs

index bf8c15c20abbd0e09641bb0cf0321fb515891e39..c3bf7a6d12a67bee1f69db6e58153d8765b4a6fe 100644 (file)
@@ -109,7 +109,7 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
             let i: uint = from_str(s.slice_to(s.len() - rest.len())).unwrap();
             s = rest.slice_from(i);
             rest = rest.slice_to(i);
-            loop {
+            while rest.len() > 0 {
                 if rest.starts_with("$") {
                     macro_rules! demangle(
                         ($($pat:expr => $demangled:expr),*) => ({
@@ -144,8 +144,12 @@ macro_rules! demangle(
                         "$x5d" => "]"
                     )
                 } else {
-                    try!(writer.write_str(rest));
-                    break;
+                    let idx = match rest.find('$') {
+                        None => rest.len(),
+                        Some(i) => i,
+                    };
+                    try!(writer.write_str(rest.slice_to(idx)));
+                    rest = rest.slice_from(idx);
                 }
             }
         }
@@ -774,4 +778,10 @@ fn demangle_dollars() {
         t!("_ZN8$UP$test4foobE", "~test::foob");
         t!("_ZN8$x20test4foobE", " test::foob");
     }
+
+    #[test]
+    fn demangle_many_dollars() {
+        t!("_ZN12test$x20test4foobE", "test test::foob");
+        t!("_ZN12test$UP$test4foobE", "test~test::foob");
+    }
 }