aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gallacher <tomgallacher23@gmail.com>2014-01-10 19:53:47 +0000
committerFedor Indutny <fedor.indutny@gmail.com>2014-01-10 21:13:46 +0000
commit38a07a929bb551451b21513ce6262f416651d12b (patch)
tree00a602f20be43d2a269f852a03ff15d4da32d297
parent5106cadffba559ac788a8c1b9a555a6d192d95aa (diff)
downloadandroid-node-v8-38a07a929bb551451b21513ce6262f416651d12b.tar.gz
android-node-v8-38a07a929bb551451b21513ce6262f416651d12b.tar.bz2
android-node-v8-38a07a929bb551451b21513ce6262f416651d12b.zip
util: handle escaped forward slashes correctly
Fixes #6835
-rw-r--r--lib/util.js3
-rw-r--r--test/simple/test-util-inspect.js15
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/util.js b/lib/util.js
index a03e87449c..e3f47234de 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -413,7 +413,8 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
} else {
name = name.replace(/'/g, "\\'")
.replace(/\\"/g, '"')
- .replace(/(^"|"$)/g, "'");
+ .replace(/(^"|"$)/g, "'")
+ .replace(/\\\\/g, '\\');
name = ctx.stylize(name, 'string');
}
}
diff --git a/test/simple/test-util-inspect.js b/test/simple/test-util-inspect.js
index 86eceea932..474410e803 100644
--- a/test/simple/test-util-inspect.js
+++ b/test/simple/test-util-inspect.js
@@ -110,6 +110,21 @@ assert.doesNotThrow(function() {
var x = { inspect: util.inspect };
assert.ok(util.inspect(x).indexOf('inspect') != -1);
+// util.inspect should not display the escaped value of a key.
+var w = {
+ '\\': 1,
+ '\\\\': 2,
+ '\\\\\\': 3,
+ '\\\\\\\\': 4,
+}
+
+var y = ['a', 'b', 'c'];
+y['\\\\\\'] = 'd';
+
+assert.ok(util.inspect(w),
+ '{ \'\\\': 1, \'\\\\\': 2, \'\\\\\\\': 3, \'\\\\\\\\\': 4 }');
+assert.ok(util.inspect(y), '[ \'a\', \'b\', \'c\', \'\\\\\\\': \'d\' ]');
+
// util.inspect.styles and util.inspect.colors
function test_color_style(style, input, implicit) {
var color_name = util.inspect.styles[style];