Skip to content

Commit 52e3843

Browse files
committed
fix(orderBy): support string predicates containing non-ident characters
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
1 parent a8c1d9c commit 52e3843

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/ng/filter/orderBy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ function orderByFilter($parse){
7373
descending = predicate.charAt(0) == '-';
7474
predicate = predicate.substring(1);
7575
}
76-
get = $parse(predicate);
76+
get = $parse('item["'+predicate+'"]');
7777
}
7878
return reverseComparator(function(a,b){
79-
return compare(get(a),get(b));
79+
return compare(get(a, {'item': a}),get(b, {'item': b}));
8080
}, descending);
8181
});
8282
var arrayCopy = [];

test/ng/filter/orderBySpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ describe('Filter: orderBy', function() {
3131
toEqual([{a:2, b:1},{a:15, b:1}]);
3232
});
3333

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

0 commit comments

Comments
 (0)