Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doubled array entry using index '' in node v8.4.0 #15159

Closed
lucaelin opened this issue Sep 3, 2017 · 12 comments
Closed

Doubled array entry using index '' in node v8.4.0 #15159

lucaelin opened this issue Sep 3, 2017 · 12 comments
Labels
test Issues and PRs related to the tests. util Issues and PRs related to the built-in util module.

Comments

@lucaelin
Copy link

lucaelin commented Sep 3, 2017

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' ]
@TimothyGu
Copy link
Member

This is because of a bug when printing the array, not because the array actually has a duplicated property.

/cc @BridgeAR

@addaleax addaleax added the util Issues and PRs related to the built-in util module. label Sep 3, 2017
@keangkai
Copy link

keangkai commented Sep 3, 2017

I think array is duplicate but I'm not sure

@mscdex
Copy link
Contributor

mscdex commented Sep 3, 2017

It's not possible to have duplicate keys for normal JS objects like that (the "exception" being Map instances), so if anything there is a bug in util.inspect() as @TimothyGu mentioned.

@mscdex mscdex added the v8.x label Sep 3, 2017
@targos targos self-assigned this Sep 3, 2017
@targos
Copy link
Member

targos commented Sep 3, 2017

I'm looking at this

@targos
Copy link
Member

targos commented Sep 3, 2017

Well, actually it seems to be already fixed on master. Can someone else confirm?

@benjamingr
Copy link
Member

benjamingr commented Sep 3, 2017

@targos looks fixed in master on macOS:

~/Documents/OpenSource/node [master] $ ./out/Release/node
> var a = []
undefined
> a[''] = 'foo'
'foo'
> console.log(a)
[ '': 'foo' ]
undefined
> 
(To exit, press ^C again or type .exit)
> 
~/Documents/OpenSource/node [master] $ node -v
v8.4.0
~/Documents/OpenSource/node [master] $ node
> var a = []
undefined
> a[''] = 'foo'
'foo'
> console.log(a)
[ '': 'foo', '': 'foo' ]
undefined
> 

Thanks for the report @chancho4321 this bug appears to have been fixed already - thanks anyway, reporting was the right thing to do :)

@TimothyGu
Copy link
Member

That's great to hear! We should make sure to have a test case for it if one doesn't yet exist.

@BridgeAR
Copy link
Member

BridgeAR commented 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.

@BridgeAR BridgeAR added the good first issue Issues that are suitable for first-time contributors. label Sep 3, 2017
@addaleax addaleax added test Issues and PRs related to the tests. and removed v8.x labels Sep 3, 2017
@mscdex
Copy link
Contributor

mscdex commented 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
Copy link
Member

addaleax commented 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.)

@Trott
Copy link
Member

Trott commented Sep 8, 2017

There's a PR open for this so I'm removing the good first contribution label.

@Trott Trott removed the good first issue Issues that are suitable for first-time contributors. label Sep 8, 2017
BridgeAR pushed a commit that referenced this issue Sep 11, 2017
PR-URL: #15258
Refs: #15159
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@BridgeAR
Copy link
Member

Fixed by 21a3ae3

addaleax pushed a commit to addaleax/node that referenced this issue Sep 13, 2017
PR-URL: nodejs#15258
Refs: nodejs#15159
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
jasnell pushed a commit that referenced this issue Sep 20, 2017
PR-URL: #15258
Refs: #15159
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this issue Oct 17, 2017
PR-URL: #15258
Refs: #15159
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this issue Oct 25, 2017
PR-URL: #15258
Refs: #15159
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Issues and PRs related to the tests. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

9 participants