Doubled array entry using index '' in node v8.4.0 #15159
Copy link
Copy link
Closed
Labels
testIssues and PRs related to Node.js core tests and test infrastructure.Issues and PRs related to Node.js core tests and test infrastructure.utilIssues and PRs related to the built-in util module.Issues and PRs related to the built-in util module.
Description
- Version: v8.4.0
- Platform: Linux hostname 4.4.0-93-lowlatency test-require-resolve: use case insensitive compare #116-Ubuntu SMP PREEMPT Fri Aug 11 22:13:00 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
As of node v8.4.0, assigning a value to the array index '' causes a duplicate entry to be created. The duplicate disappears (and cannot be recreated) as soon as a value is assigned to a numerical index.
let x = [];
x[''] = 'foo';
console.log(x);
// [ '': 'foo', '': 'foo' ]
console.log(x[0]);
// undefined
x[0] = 'bar';
console.log(x);
// [ 'bar', '': 'foo' ]
x[''] = 'baz';
console.log(x);
// [ 'bar', '': 'baz' ]
Metadata
Metadata
Assignees
Labels
testIssues and PRs related to Node.js core tests and test infrastructure.Issues and PRs related to Node.js core tests and test infrastructure.utilIssues and PRs related to the built-in util module.Issues and PRs related to the built-in util module.
Activity
TimothyGu commentedon Sep 3, 2017
This is because of a bug when printing the array, not because the array actually has a duplicated property.
/cc @BridgeAR
keangkai commentedon Sep 3, 2017
I think array is duplicate but I'm not sure
mscdex commentedon Sep 3, 2017
It's not possible to have duplicate keys for normal JS objects like that (the "exception" being
Mapinstances), so if anything there is a bug inutil.inspect()as @TimothyGu mentioned.targos commentedon Sep 3, 2017
I'm looking at this
targos commentedon Sep 3, 2017
Well, actually it seems to be already fixed on
master. Can someone else confirm?benjamingr commentedon Sep 3, 2017
@targos looks fixed in master on macOS:
Thanks for the report @chancho4321 this bug appears to have been fixed already - thanks anyway, reporting was the right thing to do :)
TimothyGu commentedon Sep 3, 2017
That's great to hear! We should make sure to have a test case for it if one doesn't yet exist.
BridgeAR commentedon Sep 3, 2017
This got fixed by 3a886ff. Thanks for the report as this is a interesting edge case. It could only happen if the array contained a empty string as key and no regular entry. As @TimothyGu pointed out it would be nice to add a additional test case.
Therefore I am adding the good first contribution label.
mscdex commentedon Sep 3, 2017
@addaleax Shouldn't this still be tagged with 'v8.x' since that is where the issue still occurs (the aforementioned commit is not present in either the 'v8.x-staging' or 'v8.x' branches)?
addaleax commentedon Sep 3, 2017
@mscdex I can only speak for me, but as somebody who put together a number of the previous v8.x releases, having that label on issues that were also affecting
master(which is our implied default, iirc) is confusing, because it gives the impression that some special care is needed for that release line. Unlike with LTS, we land anything in v8.x that also landed in master and is not semver-major by default, so this wouldn’t have been forgotten. Other releasers might disagree, and I’m not saying that I’m right about this being the best approach.(It’s totally fine to add that label for bugs in LTS, or for bugs that only occur in specific release lines, of course.)
test: check util.inspect for array having empty string as key
Trott commentedon Sep 8, 2017
There's a PR open for this so I'm removing the
good first contributionlabel.test: check inspect array with empty string key
BridgeAR commentedon Sep 11, 2017
Fixed by 21a3ae3
test: check inspect array with empty string key
test: check inspect array with empty string key
test: check inspect array with empty string key
test: check inspect array with empty string key