Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 3bc4e7f

Browse files
tomdccvojtajina
authored andcommitted
fix(filter): filter on false properties
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 #2797.
1 parent 3a65822 commit 3bc4e7f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ng/filter/filter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function filterFilter() {
183183
})();
184184
} else {
185185
(function() {
186-
if (!expression[key]) return;
186+
if (typeof(expression[key]) == 'undefined') { return; }
187187
var path = key;
188188
predicates.push(function(value) {
189189
return search(getter(value,path), expression[path]);

test/ng/filter/filterSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ describe('Filter: filter', function() {
6060
expect(filter(items, {first:'misko', last:'hevery'})[0]).toEqual(items[0]);
6161
});
6262

63+
it('should support boolean properties', function() {
64+
var items = [{name: 'tom', current: true},
65+
{name: 'demi', current: false},
66+
{name: 'sofia'}];
67+
68+
expect(filter(items, {current:true}).length).toBe(1);
69+
expect(filter(items, {current:true})[0].name).toBe('tom');
70+
expect(filter(items, {current:false}).length).toBe(1);
71+
expect(filter(items, {current:false})[0].name).toBe('demi');
72+
});
73+
6374
it('should support negation operator', function() {
6475
var items = ['misko', 'adam'];
6576

0 commit comments

Comments
 (0)