wy-ei / vue-filter

:v: A collection of Vue.js filter. [Depressed]
MIT License
353 stars 40 forks source link

Collection Filters 'join', if the "express" is undefined, NaN, null, TypeError will throw #5

Closed laomagege closed 8 years ago

laomagege commented 8 years ago

var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1; util.isArrayLike = function(obj) { var length = obj ? obj['length'] //this line of code will have problem.

var length = obj ? obj['length'] : -1; //could change as this to fix this issue, (null, NaN, undefined length will be -1)

wy-ei commented 8 years ago

@laomagege I forget check the type of the parameter obj , so if it's not a Object an error will be throw. I think I can fix this bug by sample change the code like this :

util.isArrayLike = function(obj) {
    if(typeof obj !== 'object' || !obj){
        return false;
    }
    var length = obj.length;
    return typeof length === 'number'
        && length % 1 === 0 && length >= 0 && length <= MAX_ARRAY_INDEX;
};
laomagege commented 8 years ago

Yes, sounds good.