Created
December 7, 2009 04:45
-
-
Save xaviershay/250619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From d5d522adb48cb3c42a7bd86cc019f9f2fca32166 Mon Sep 17 00:00:00 2001 | |
From: Xavier Shay <xavier@rhnh.net> | |
Date: Mon, 7 Dec 2009 15:44:41 +1100 | |
Subject: [PATCH] sys.inspect prints out special chars correctly (\n, \u0001, etc...) | |
--- | |
lib/sys.js | 2 +- | |
test/mjsunit/test-sys.js | 2 ++ | |
2 files changed, 3 insertions(+), 1 deletions(-) | |
diff --git a/lib/sys.js b/lib/sys.js | |
index 9c4dc6d..a2070b1 100644 | |
--- a/lib/sys.js | |
+++ b/lib/sys.js | |
@@ -82,7 +82,7 @@ exports.inherits = process.inherits; | |
*/ | |
var formatter = function(value, indent, parents) { | |
switch(typeof(value)) { | |
- case 'string': return '"' + value + '"'; | |
+ case 'string': return JSON.stringify(value); | |
case 'number': return '' + value; | |
case 'function': return '[Function]'; | |
case 'boolean': return '' + value; | |
diff --git a/test/mjsunit/test-sys.js b/test/mjsunit/test-sys.js | |
index 14ce551..1c114d8 100644 | |
--- a/test/mjsunit/test-sys.js | |
+++ b/test/mjsunit/test-sys.js | |
@@ -10,6 +10,8 @@ assert.equal("[Function]", inspect(function() {})); | |
assert.equal('undefined', inspect(undefined)); | |
assert.equal('null', inspect(null)); | |
+assert.equal("\"\\n\\u0001\"", inspect("\n\u0001")); | |
+ | |
assert.equal('[]', inspect([])); | |
assert.equal('[\n 1,\n 2\n]', inspect([1, 2])); | |
assert.equal('[\n 1,\n [\n 2,\n 3\n ]\n]', inspect([1, [2, 3]])); | |
-- | |
1.6.2.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment