Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Closes GH-310 Format slashes properly
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs authored and ry committed Apr 2, 2011
1 parent a7254f3 commit 4d64f36
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/util.js
Expand Up @@ -118,9 +118,9 @@ exports.inspect = function(obj, showHidden, depth, colors) {
return stylize('undefined', 'undefined'); return stylize('undefined', 'undefined');


case 'string': case 'string':
var simple = JSON.stringify(value).replace(/'/g, "\\'") var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
.replace(/\\"/g, '"') .replace(/'/g, "\\'")
.replace(/(^"|"$)/g, "'"); .replace(/\\"/g, '"') + '\'';
return stylize(simple, 'string'); return stylize(simple, 'string');


case 'number': case 'number':
Expand Down
3 changes: 2 additions & 1 deletion test/simple/test-console.js
Expand Up @@ -31,11 +31,12 @@ global.process.stdout.write = function(string) {
console.log('foo'); console.log('foo');
console.log('foo', 'bar'); console.log('foo', 'bar');
console.log('%s %s', 'foo', 'bar', 'hop'); console.log('%s %s', 'foo', 'bar', 'hop');
console.log({slashes: '\\\\'})


global.process.stdout.write = stdout_write; global.process.stdout.write = stdout_write;
assert.equal('foo\n', strings.shift()); assert.equal('foo\n', strings.shift());
assert.equal('foo bar\n', strings.shift()); assert.equal('foo bar\n', strings.shift());
assert.equal('foo bar hop\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")); assert.equal(true, process.stderr.write("hello world"));

0 comments on commit 4d64f36

Please sign in to comment.