gwatts / jquery.sparkline

A plugin for the jQuery javascript library to generate small sparkline charts directly in the browser
http://omnipotent.net/jquery.sparkline/
1.24k stars 278 forks source link

Possible bug in $.RangeMapClass #136

Open patrickmayer0 opened 9 years ago

patrickmayer0 commented 9 years ago

Hi, I think there is a bug in the $.RangeMapClass (version 2.1.2), in the get function:

get: function (value) { var rangelist = this.rangelist, i, range, result; if ((result = this.map[value]) !== undefined) { return result; } if (rangelist) { for (i = rangelist.length; i--;) { range = rangelist[i]; if (range[0] <= value && range[1] >= value) { return range[2]; } } } return undefined; }

In this code, if the value is null, the first range is always returned.

Comparing null to a numerical value is acceptable in javascript but probably not in this context.

A check for null / undefined here: if (rangelist) ... would solve this problem.

Regards, Patrick