Sparkline icon indicating copy to clipboard operation
Sparkline copied to clipboard

Handling a few edge case errors

Open offsky opened this issue 5 years ago • 0 comments

Thanks for making this simple utility. Exactly what I needed to save a bit of work.

I made a small fix to handle some edge cases. If you approve of these changes and want a pull request, I would be happy to make one. Or you can copy and paste from below.

Trailing or leading commas or non-numeric values. Maybe I am sloppy and don't handle an off by one error when constructing the data parameter and send something like data="1,2,3,4," with a trailing comma. Or maybe I goof up and put a non-value in the array "data=1,2,NaN,4". Maybe I should fix my code, but a fix to your code is really easy too. Just insert these lines near the top:

foreach($data as $k=>$v) {
    if(!is_numeric($v)) unset($data[$k]);
}
$data = array_values($data);

offsky avatar Oct 27 '20 17:10 offsky