From 4d64f363385be9d5e83ededd70faf91ebc6e792b Mon Sep 17 00:00:00 2001 From: isaacs 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 | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/util.js b/lib/util.js index b824a71a714..4241ba0f074 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 b7def76c406..e9fd5e6c0fc 100644 --- a/test/simple/test-console.js +++ b/test/simple/test-console.js @@ -31,11 +31,12 @@ 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()); assert.equal(true, process.stderr.write("hello world"));