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

fix(orderBy): support string predicates containing non-ident characters #6144

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ng/filter/orderBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ function orderByFilter($parse){
predicate = predicate.substring(1);
}
get = $parse(predicate);
if (get.constant) {
var key = get();
return reverseComparator(function(a,b) {
return compare(a[key], b[key]);
}, descending);
}
}
return reverseComparator(function(a,b){
return compare(get(a),get(b));
Expand Down
12 changes: 12 additions & 0 deletions test/ng/filter/orderBySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,16 @@ 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}]);
expect(orderBy([{"원": 76000}, {"원": 31000}, {"원": 156000}], '"원"'))
.toEqualData([{"원": 31000}, {"원": 76000}, {"원": 156000}])
});

it('should throw if quoted string predicate is quoted incorrectly', function() {
expect(function() {
return orderBy([{"Tip %": .15}, {"Tip %": .25}, {"Tip %": .40}], '"Tip %\'');
}).toThrow();
});
});