Skip to content

Commit

Permalink
fix(filter): filter on false properties
Browse files Browse the repository at this point in the history
Code was evaluating !expression[key] while attempting to
see if the key was present, but this was evaluating to true for
false values as well as missing keys.

Closes angular#2797.
  • Loading branch information
tomdcc committed Aug 15, 2013
1 parent 60af2ec commit 5c7063c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/filter/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function filterFilter() {
})();
} else {
(function() {
if (!expression[key]) return;
if (typeof(expression[key]) == 'undefined') { return; }
var path = key;
predicates.push(function(value) {
return search(getter(value,path), expression[path]);
Expand Down
11 changes: 11 additions & 0 deletions test/ng/filter/filterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ describe('Filter: filter', function() {
expect(filter(items, {first:'misko', last:'hevery'})[0]).toEqual(items[0]);
});

it('should support boolean properties', function() {
var items = [{name: 'tom', current: true},
{name: 'demi', current: false},
{name: 'sofia'}];

expect(filter(items, {current:true}).length).toBe(1);
expect(filter(items, {current:true})[0].name).toBe('tom');
expect(filter(items, {current:false}).length).toBe(1);
expect(filter(items, {current:false})[0].name).toBe('demi');
});

it('should support negation operator', function() {
var items = ['misko', 'adam'];

Expand Down

0 comments on commit 5c7063c

Please sign in to comment.