Skip to content

Commit 7a74a50

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 7a74a50

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-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

+6
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ 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+
expect(orderBy([{"원": 76000}, {"원": 31000}, {"원": 156000}], "원"))
38+
.toEqualData([{"원": 31000}, {"원": 76000}, {"원": 156000}])
39+
});
3440
});

0 commit comments

Comments
 (0)