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
Update PolyUtil.js #8840
Update PolyUtil.js #8840
Conversation
Replace for..in to avoid TypeError: Cannot read properties of null (reading 'lat') with extra attributes of array
Can you provide an example of how to reproduce this bug? |
I found it in a complicated piece o code, but the principle that caused
this bug was the following:
// Somewhere deep in your JavaScript library...Array.prototype.foo = 1;
// Now you have no idea what the below code will do.var a = [1, 2, 3,
4, 5];for (var x in a){
// Now foo is a part of EVERY array and
// will show up here as a value of 'x'.
console.log(x);
}
/* Will display:
0
1
2
3
4
foo
*/
Jon Koops ***@***.***> escreveu em qui., 9/02/2023 às 18:59 :
Can you provide an example of how to reproduce this bug?
—
Reply to this email directly, view it on GitHub
<#8840 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4IKB4ZKFMGZJXO5RNDKLWWU5BPANCNFSM6AAAAAAUWYZWTA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
David Vaz, PhD
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidmgvaz could you add a regression test for this?
I am not too comfortable to create that. I just found a common error, and decided to warn about it. I literally changed 2 lines of code, easy to check by any reviewer. Can you please help? |
I added the same fix to Another solutions woule be
|
True, and safer for partially filled arrays e.g
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering, why is it a for ... in
loop in the first place, iterating over an array? Looks like a mistake that slipped in earlier. This probably should be a for ... of
, right?
even better. Perfect. |
Co-authored-by: Florian Bischof <design.falke@gmail.com>
@Falke-Design @mourner a quick enable of the Although these are of course not all bugs like this one, they would have the potential to be. Perhaps we should enable this rule and replace all existing loops with |
I have in mind that not all usages of |
Yeah I wonder how many we can replace and which will remain. I've created an issue for it (#8843) with a 'help wanted' label, since it's not really high prio, but should be looked into by someone. |
Replace for..in to avoid TypeError: Cannot read properties of null (reading 'lat') with extra attributes of array