File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -170,18 +170,18 @@ function orderByFilter($parse) {
170170 if ( t1 === t2 && t1 === "object" ) {
171171 // If types are both numbers, emulate abstract ToPrimitive() operation
172172 // in order to get primitive values suitable for comparison
173- t1 = typeof ( v1 = v1 . valueOf ( ) ) ;
174- t2 = typeof ( v2 = v2 . valueOf ( ) ) ;
173+ t1 = typeof ( v1 . valueOf ? v1 = v1 . valueOf ( ) : v1 ) ;
174+ t2 = typeof ( v2 . valueOf ? v2 = v2 . valueOf ( ) : v2 ) ;
175175 if ( t1 === t2 && t1 === "object" ) {
176176 // Object.prototype.valueOf will return the original object, by
177177 // default. If we do not receive a primitive value, use ToString()
178178 // instead.
179- t1 = typeof ( v1 = v1 . toString ( ) ) ;
180- t2 = typeof ( v2 = v2 . toString ( ) ) ;
179+ t1 = typeof ( v1 . toString ? v1 = v1 . toString ( ) : v1 ) ;
180+ t2 = typeof ( v2 . toString ? v2 = v2 . toString ( ) : v2 ) ;
181181
182182 // If the end result of toString() for each item is the same, do not
183183 // perform relational comparison, and do not re-order objects.
184- if ( t1 === t2 && v1 === v2 ) return 0 ;
184+ if ( t1 === t2 && v1 === v2 || t1 === "object" ) return 0 ;
185185 }
186186 }
187187 if ( t1 === t2 ) {
Original file line number Diff line number Diff line change @@ -115,6 +115,16 @@ describe('Filter: orderBy', function() {
115115 ] ;
116116 expect ( orderBy ( array ) ) . toEqualData ( array ) ;
117117 } ) ;
118+
119+
120+ it ( 'should not reverse array of objects with null prototype and no predicate' , function ( ) {
121+ var array = [ 2 , 1 , 4 , 3 ] . map ( function ( id ) {
122+ var obj = Object . create ( null ) ;
123+ obj . id = id ;
124+ return obj ;
125+ } ) ;
126+ expect ( orderBy ( array ) ) . toEqualData ( array ) ;
127+ } ) ;
118128 } ) ;
119129
120130
@@ -232,5 +242,15 @@ describe('Filter: orderBy', function() {
232242 ] ;
233243 expect ( orderBy ( array ) ) . toEqualData ( array ) ;
234244 } ) ;
245+
246+
247+ it ( 'should not reverse array of objects with null prototype and no predicate' , function ( ) {
248+ var array = [ 2 , 1 , 4 , 3 ] . map ( function ( id ) {
249+ var obj = Object . create ( null ) ;
250+ obj . id = id ;
251+ return obj ;
252+ } ) ;
253+ expect ( orderBy ( array ) ) . toEqualData ( array ) ;
254+ } ) ;
235255 } ) ;
236256} ) ;
You can’t perform that action at this time.
0 commit comments