X Tutup
Skip to content

Commit bced3aa

Browse files
itslennyvsavkin
authored andcommitted
fix(ListWrapper): make list slice in dart return empty list if start and end are inverted like JS
1 parent 105db02 commit bced3aa

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

modules/angular2/src/core/facade/collection.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ class ListWrapper {
182182
}
183183

184184
static List slice(List l, [int from = 0, int to]) {
185+
//in JS if from > to an empty array is returned
186+
if(to != null && from > to) {
187+
return [];
188+
}
185189
return l.sublist(_startOffset(l, from), _endOffset(l, to));
186190
}
187191

modules/angular2/test/core/facade/collection_spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ export function main() {
6262

6363
it('should support negative end',
6464
() => { expect(ListWrapper.slice(l, -3, -1)).toEqual([2, 3]); });
65+
66+
it('should return empty list if start is greater than end',
67+
() => { expect(ListWrapper.slice(l, 4, 2)).toEqual([]); });
6568
});
6669

6770
describe('indexOf', () => {

0 commit comments

Comments
 (0)
X Tutup