Skip to content

Commit 4d64f36

Browse files
isaacsry
authored andcommitted
Closes GH-310 Format slashes properly
1 parent a7254f3 commit 4d64f36

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/util.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ exports.inspect = function(obj, showHidden, depth, colors) {
118118
return stylize('undefined', 'undefined');
119119

120120
case 'string':
121-
var simple = JSON.stringify(value).replace(/'/g, "\\'")
122-
.replace(/\\"/g, '"')
123-
.replace(/(^"|"$)/g, "'");
121+
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
122+
.replace(/'/g, "\\'")
123+
.replace(/\\"/g, '"') + '\'';
124124
return stylize(simple, 'string');
125125

126126
case 'number':

test/simple/test-console.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ global.process.stdout.write = function(string) {
3131
console.log('foo');
3232
console.log('foo', 'bar');
3333
console.log('%s %s', 'foo', 'bar', 'hop');
34+
console.log({slashes: '\\\\'})
3435

3536
global.process.stdout.write = stdout_write;
3637
assert.equal('foo\n', strings.shift());
3738
assert.equal('foo bar\n', strings.shift());
3839
assert.equal('foo bar hop\n', strings.shift());
39-
40+
assert.equal("{ slashes: '\\\\\\\\' }\n", strings.shift());
4041

4142
assert.equal(true, process.stderr.write("hello world"));

0 commit comments

Comments
 (0)