From 8594c4719015e50c977b4817da8e38edadb2a4d0 Mon Sep 17 00:00:00 2001 From: Tobias Wentzlaff Date: Tue, 10 Apr 2018 22:30:49 +0200 Subject: [PATCH] escaping octal literals correctly for using in strict mode --- lib/eyes.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/eyes.js b/lib/eyes.js index b57b7b0..0e13756 100644 --- a/lib/eyes.js +++ b/lib/eyes.js @@ -52,7 +52,7 @@ eyes.inspect = function (obj, label, options) { if (options.stream) { return this.print(stringify(obj, options), label, options); } else { - return stringify(obj, options) + (options.styles ? '\033[39m' : ''); + return stringify(obj, options) + (options.styles ? '\\033[39m' : ''); } }; @@ -65,7 +65,7 @@ eyes.inspect = function (obj, label, options) { // length manually. eyes.print = function (str, label, options) { for (var c = 0, i = 0; i < str.length; i++) { - if (str.charAt(i) === '\033') { i += 4 } // `4` because '\033[25m'.length + 1 == 5 + if (str.charAt(i) === '\\033') { i += 4 } // `4` because '\033[25m'.length + 1 == 5 else if (c === options.maxLength) { str = str.slice(0, i - 1) + '…'; break; @@ -73,7 +73,7 @@ eyes.print = function (str, label, options) { } return options.stream.write.call(options.stream, (label ? this.stylize(label, options.styles.label, options.styles) + ': ' : '') + - this.stylize(str, options.styles.all, options.styles) + '\033[0m' + "\n"); + this.stylize(str, options.styles.all, options.styles) + '\\033[0m' + "\n"); }; // Apply a style to a string, eventually, @@ -96,8 +96,8 @@ eyes.stylize = function (str, style, styles) { if (style && codes[style]) { endCode = (codes[style][1] === 39 && styles.all) ? codes[styles.all][0] : codes[style][1]; - return '\033[' + codes[style][0] + 'm' + str + - '\033[' + endCode + 'm'; + return '\\033[' + codes[style][0] + 'm' + str + + '\\033[' + endCode + 'm'; } else { return str } };