buche / leaflet-openweathermap

A JavaScript library for including OpenWeatherMap's layers and OWM's current city/station data in leaflet based maps without hassle.
259 stars 132 forks source link

legend iterator tries to print array prototypes as image sources #8

Closed mikeatlas closed 9 years ago

mikeatlas commented 9 years ago

On line 200/201:

for (var idx in this._legendContainer) {
    var imgPath = this._legendContainer[idx];
        //...

If the Array prototype has been extended to have additional functions, those functions are returned by name as idx values. You then end up with broken image src attributes containing javascript source code from that function, for example in my case:

<div class="owm-legend-item" style="float: left; margin-right: 10px;">
<img src="function (callback) {
        var arrayClone, sections;
        sections = [];
        arrayClone = this.slice(0);
        $.each(arrayClone, (function(_this) {
       // ... etc
      }" border="0">
</div>

You could fix this pretty easily though with an isNaN check:

for (var idx in this._legendContainer) {
        if (isNan(idx)) { continue; }
        //...

via- https://github.com/buche/leaflet-openweathermap/blob/master/leaflet-openweathermap.js#L200-L201

mikeatlas commented 9 years ago

PS: Thanks for the great plugin. It's super useful! I'll make a PR if you'd like me to fix this instead. Otherwise I need to fork it for the fix, as I need it soon.

mikeatlas commented 9 years ago

thank you!