fix case where input.length may be undefined