fix(filterFilter): don't match primitive sub-expressions against any prop

Basically, implement the logic detailed in the 2nd point of
https://github.com/angular/angular.js/pull/9757#issuecomment-63544399
This commit is contained in:
Georgios Kalpakas
2014-11-24 16:32:06 +02:00
committed by Caitlin Potter
parent 5ced914cc8
commit a75537d461
2 changed files with 42 additions and 15 deletions

View File

@@ -136,6 +136,17 @@ describe('Filter: filter', function() {
});
it('should respect the depth level of a "$" property', function() {
var items = [{person: {name: 'Annet', email: 'annet@example.com'}},
{person: {name: 'Billy', email: 'me@billy.com'}},
{person: {name: 'Joan', email: {home: 'me@joan.com', work: 'joan@example.net'}}}];
var expr = {person: {$: 'net'}};
expect(filter(items, expr).length).toBe(1);
expect(filter(items, expr)).toEqual([items[0]]);
});
it('should respect the nesting level of "$"', function() {
var items = [{supervisor: 'me', person: {name: 'Annet', email: 'annet@example.com'}},
{supervisor: 'me', person: {name: 'Billy', email: 'me@billy.com'}},
@@ -314,6 +325,13 @@ describe('Filter: filter', function() {
describe('should support comparator', function() {
it('not consider `object === "[object Object]"` in non-strict comparison', function() {
var items = [{test: {}}];
var expr = '[object';
expect(filter(items, expr).length).toBe(0);
});
it('as equality when true', function() {
var items = ['misko', 'adam', 'adamson'];
var expr = 'adam';
@@ -395,7 +413,7 @@ describe('Filter: filter', function() {
return isString(actual) && isString(expected) && (actual.indexOf(expected) === 0);
};
expr = {details: {email: 'admin@example.com', role: 'admn'}};
expr = {details: {email: 'admin@example.com', role: 'min'}};
expect(filter(items, expr, comp)).toEqual([]);
expr = {details: {email: 'admin@example.com', role: 'adm'}};