Guest User

Untitled

a guest
Apr 21st, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. From d5d522adb48cb3c42a7bd86cc019f9f2fca32166 Mon Sep 17 00:00:00 2001
  2. From: Xavier Shay <xavier@rhnh.net>
  3. Date: Mon, 7 Dec 2009 15:44:41 +1100
  4. Subject: [PATCH] sys.inspect prints out special chars correctly (\n, \u0001, etc...)
  5.  
  6. ---
  7. lib/sys.js | 2 +-
  8. test/mjsunit/test-sys.js | 2 ++
  9. 2 files changed, 3 insertions(+), 1 deletions(-)
  10.  
  11. diff --git a/lib/sys.js b/lib/sys.js
  12. index 9c4dc6d..a2070b1 100644
  13. --- a/lib/sys.js
  14. +++ b/lib/sys.js
  15. @@ -82,7 +82,7 @@ exports.inherits = process.inherits;
  16. */
  17. var formatter = function(value, indent, parents) {
  18. switch(typeof(value)) {
  19. - case 'string': return '"' + value + '"';
  20. + case 'string': return JSON.stringify(value);
  21. case 'number': return '' + value;
  22. case 'function': return '[Function]';
  23. case 'boolean': return '' + value;
  24. diff --git a/test/mjsunit/test-sys.js b/test/mjsunit/test-sys.js
  25. index 14ce551..1c114d8 100644
  26. --- a/test/mjsunit/test-sys.js
  27. +++ b/test/mjsunit/test-sys.js
  28. @@ -10,6 +10,8 @@ assert.equal("[Function]", inspect(function() {}));
  29. assert.equal('undefined', inspect(undefined));
  30. assert.equal('null', inspect(null));
  31.  
  32. +assert.equal("\"\\n\\u0001\"", inspect("\n\u0001"));
  33. +
  34. assert.equal('[]', inspect([]));
  35. assert.equal('[\n 1,\n 2\n]', inspect([1, 2]));
  36. assert.equal('[\n 1,\n [\n 2,\n 3\n ]\n]', inspect([1, [2, 3]]));
  37. --
  38. 1.6.2.4
Add Comment
Please, Sign In to add comment