Permalink
Browse files

Fixed filtering on contains and excludes

  • Loading branch information...
1 parent 3676ed1 commit b16713b2b8e41dccd1c11b1a25a63bdda37b4afe @kriszyp kriszyp committed Dec 1, 2010
Showing with 11 additions and 12 deletions.
  1. +10 −10 lib/js-array.js
  2. +1 −2 test/js-array.js
View
@@ -54,8 +54,8 @@ exports.operators = {
}),
contains: filter(function(array, value){
if(typeof value == "function"){
- return array instanceof Array && array.some(function(i){
- return value([i]).length;
+ return array instanceof Array && array.some(function(v){
+ return value.call([v]).length;
});
}
else{
@@ -64,8 +64,8 @@ exports.operators = {
}),
excludes: filter(function(array, value){
if(typeof value == "function"){
- return !array.some(function(i){
- return value([i]).length;
+ return !array.some(function(v){
+ return value.call([v]).length;
});
}
else{
@@ -351,18 +351,18 @@ function query(query, options, target){
// item['foo.bar'] ==> (item && item.foo && item.foo.bar && ...)
var path = value.args[0];
var target = value.args[1];
- if(path instanceof Array){
- var item = "";
+ if (typeof target == "undefined"){
+ var item = "item";
+ target = path;
+ }else if(path instanceof Array){
+ var item = "item";
var escaped = [];
for(var i = 0;i < path.length; i++){
escaped.push(stringify(path[i]));
item +="&&item[" + escaped.join("][") + ']';
}
- }else if (typeof path == "undefined"){
- var item = "";
- target = path;
}else{
- var item = "&&item[" + stringify(path) + "]";
+ var item = "item&&item[" + stringify(path) + "]";
}
// comparison to regexps are special: we cope with eq(), ne(), the others coerce regexp to string
if (value.args[1] instanceof RegExp) {
View
@@ -27,10 +27,9 @@ exports.testFiltering = function() {
assert.equal(executeQuery("out(price,(5))", {}, data).length, 1);
assert.equal(executeQuery("contains(tags,even)", {}, data).length, 1);
assert.equal(executeQuery("contains(tags,fun)", {}, data).length, 2);
- assert.equal(executeQuery("excludes(tags,fun)", {}, data).length, 1);
+ assert.equal(executeQuery("excludes(tags,fun)", {}, data).length, 0);
assert.equal(executeQuery("excludes(tags,ne(fun))", {}, data).length, 1);
assert.equal(executeQuery("excludes(tags,ne(even))", {}, data).length, 0);
- assert.equal(executeQuery("excludes(tags,ne(even))", {}, data).length, 2);
// eq() on re: should trigger .match()
assert.deepEqual(executeQuery("price=re:10", {}, data), [data[0]]);
// ne() on re: should trigger .not(.match())

0 comments on commit b16713b

Please sign in to comment.