Skip to content

Commit

Permalink
fix(orderBy): support string predicates containing non-ident characters
Browse files Browse the repository at this point in the history
The orderBy filter now allows string predicates passed to the orderBy filter to make use property
name predicates containing non-ident strings, such as spaces or percent signs, or non-latin
characters.

Closes angular#6143
  • Loading branch information
caitp committed Feb 6, 2014
1 parent a8c1d9c commit 52e3843
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ng/filter/orderBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ function orderByFilter($parse){
descending = predicate.charAt(0) == '-';
predicate = predicate.substring(1);
}
get = $parse(predicate);
get = $parse('item["'+predicate+'"]');
}
return reverseComparator(function(a,b){
return compare(get(a),get(b));
return compare(get(a, {'item': a}),get(b, {'item': b}));
}, descending);
});
var arrayCopy = [];
Expand Down
4 changes: 4 additions & 0 deletions test/ng/filter/orderBySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ describe('Filter: orderBy', function() {
toEqual([{a:2, b:1},{a:15, b:1}]);
});

it('should support string predicates with names containing non-identifier characters', function() {
expect(orderBy([{"Tip %": .25}, {"Tip %": .15}, {"Tip %": .40}], 'Tip %'))
.toEqualData([{"Tip %": .15}, {"Tip %": .25}, {"Tip %": .40}]);
});
});

0 comments on commit 52e3843

Please sign in to comment.