Fix broken pretty-printing
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Fri, 22 Jul 2011 11:42:50 -0600
changeset 443 a38658e347fc
parent 442 2c05ce66039c
child 444 de9cb2028556
Fix broken pretty-printing

We were getting double-escaping and not replacing all occurrences of
special characters.
tests.js
--- a/tests.js	Fri Jul 22 11:41:21 2011 -0600
+++ b/tests.js	Fri Jul 22 11:42:50 2011 -0600
@@ -3386,6 +3386,9 @@
 		return String(value);
 	}
 
+	value = value.replace(/\\/g, "\\\\")
+		.replace(/"/g, '\\"');
+
 	for (var i = 0; i < 32; i++) {
 		var replace = "\\";
 		switch (i) {
@@ -3422,9 +3425,9 @@
 		case 30: replace += "x1e"; break;
 		case 31: replace += "x1f"; break;
 		}
-		value = value.replace(String.fromCharCode(i), replace);
+		value = value.replace(new RegExp(String.fromCharCode(i), "g"), replace);
 	}
-	return '"' + value.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
+	return '"' + value + '"';
 }
 //@}