pgte / alfred

Node is your mansion, Alfred is your butler. Node.js key-value store
http://pgte.github.com/alfred/
MIT License
149 stars 10 forks source link

Bug in query filter logic #9

Closed davidthings closed 13 years ago

davidthings commented 13 years ago

Deep inside the query mechanism, there's a function in index_key_interceptor.js, intercept( ), whose job is to find key records in common between different clauses of an AND query. It will get called with a pile of records that have previously matched previous conditions, and another pile of records from the current condition. Its job is to find the common records. If the former is null, it just sends the latter.

The bug happens when the former list is non-null and the latter - current - list is null. Then there's an error (can't find "filter" on undefined object).

The fix is simple.

At line 3, insert

    if ( !b_keys ) return null;

So the whole thing reads:

module.exports.intercept = function(a_keys, b_keys) { if (a_keys) { if ( !b_keys ) return null; return b_keys.filter(function(b_key) { return a_keys.some(function(a_key) { return a_key.k == b_key.k; }); });
} else { return b_keys; } };

pgte commented 13 years ago

Thanks, fixed in 0.5.3!