|
62 | 62 | */
|
63 | 63 | orderByFilter.$inject = ['$parse'];
|
64 | 64 | function orderByFilter($parse){
|
| 65 | + var QUOTED_STRING_REGEXP = /^\s*(['"])([^'"]*)\1\s*$/; |
65 | 66 | return function(array, sortPredicate, reverseOrder) {
|
| 67 | + var locals; |
66 | 68 | if (!isArray(array)) return array;
|
67 | 69 | if (!sortPredicate) return array;
|
68 | 70 | sortPredicate = isArray(sortPredicate) ? sortPredicate: [sortPredicate];
|
69 | 71 | sortPredicate = map(sortPredicate, function(predicate){
|
70 |
| - var descending = false, get = predicate || identity; |
| 72 | + var descending = false, get = predicate || identity, match; |
71 | 73 | if (isString(predicate)) {
|
72 | 74 | if ((predicate.charAt(0) == '+' || predicate.charAt(0) == '-')) {
|
73 | 75 | descending = predicate.charAt(0) == '-';
|
74 | 76 | predicate = predicate.substring(1);
|
75 | 77 | }
|
| 78 | + if ((match = predicate.match(QUOTED_STRING_REGEXP))) { |
| 79 | + // If the predicate is a quoted string, it might contain special characters, and requires |
| 80 | + // a different getter expression to work correctly. |
| 81 | + locals = locals || {item: null}; |
| 82 | + get = $parse('item["'+match[2]+'"]'); |
| 83 | + return reverseComparator(function(a,b) { |
| 84 | + locals.item = a, a = get(a, locals), locals.item = b, b = get(b, locals); |
| 85 | + return compare(a, b); |
| 86 | + }, descending); |
| 87 | + } |
| 88 | + |
76 | 89 | get = $parse(predicate);
|
77 | 90 | }
|
78 | 91 | return reverseComparator(function(a,b){
|
|
0 commit comments