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"));