Created
March 29, 2011 21:41
-
-
Save isaacs/893381 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 6172f8f515ee2449d1588c881dda9ec67f47c67f Mon Sep 17 00:00:00 2001 | |
From: isaacs <i@izs.me> | |
Date: Tue, 29 Mar 2011 14:41:23 -0700 | |
Subject: [PATCH] Closes GH-310 Format slashes properly | |
--- | |
lib/util.js | 6 +++--- | |
test/simple/test-console.js | 2 ++ | |
2 files changed, 5 insertions(+), 3 deletions(-) | |
diff --git a/lib/util.js b/lib/util.js | |
index f1acd76..304e6d1 100644 | |
--- a/lib/util.js | |
+++ b/lib/util.js | |
@@ -118,9 +118,9 @@ exports.inspect = function(obj, showHidden, depth, colors) { | |
return stylize('undefined', 'undefined'); | |
case 'string': | |
- var simple = JSON.stringify(value).replace(/'/g, "\\'") | |
- .replace(/\\"/g, '"') | |
- .replace(/(^"|"$)/g, "'"); | |
+ var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') | |
+ .replace(/'/g, "\\'") | |
+ .replace(/\\"/g, '"') + '\''; | |
return stylize(simple, 'string'); | |
case 'number': | |
diff --git a/test/simple/test-console.js b/test/simple/test-console.js | |
index adde724..939a4be 100644 | |
--- a/test/simple/test-console.js | |
+++ b/test/simple/test-console.js | |
@@ -31,8 +31,10 @@ global.process.stdout.write = function(string) { | |
console.log('foo'); | |
console.log('foo', 'bar'); | |
console.log('%s %s', 'foo', 'bar', 'hop'); | |
+console.log({slashes: '\\\\'}) | |
global.process.stdout.write = stdout_write; | |
assert.equal('foo\n', strings.shift()); | |
assert.equal('foo bar\n', strings.shift()); | |
assert.equal('foo bar hop\n', strings.shift()); | |
+assert.equal("{ slashes: '\\\\\\\\' }\n", strings.shift()); | |
-- | |
1.7.2.3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment