admin-config icon indicating copy to clipboard operation
admin-config copied to clipboard

Iterating over array entries using "for .. in" breaks if Array polyfills are used

Open RichardBradley opened this issue 10 years ago • 1 comments

Hi,

I'm trying to use ng-admin with an older browser (PhantomJS 1.9, backed by Safari 5). It doesn't have Array.find, so I'm using this polyfill.

However, this breaks ng-admin in another way, because this code attempts to iterate over array entries using "for .. in":

getMappedValue(value, entry) {
    for (let i in this._maps) {
        value = this._maps[i](value, entry);
    }

    return value;
}

It's not safe to iterate over arrays in this way, see e.g. this stackoverflow answer, as any functions which have been added to Array.prototype will get returned along with all the array entries.

I believe that this and all other array loops in ng-admin and admin-config need converting to use a "for (var i = 0; i < array.length; i++) { style loop instead.

A quick grep suggests that there are a great many such loops in ng-admin and admin-config :-(

RichardBradley avatar Dec 15 '15 17:12 RichardBradley

Since ng-admin, as far as I can tell, is written in ES 2015, I believe the proper construct to use is: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of

KonstantinYegupov avatar Dec 15 '15 17:12 KonstantinYegupov