From bced3aaa176429bf3759b9e93daccddaf5404163 Mon Sep 17 00:00:00 2001 From: Lenny Date: Sun, 30 Aug 2015 17:03:37 -0700 Subject: [PATCH] fix(ListWrapper): make list slice in dart return empty list if start and end are inverted like JS --- modules/angular2/src/core/facade/collection.dart | 4 ++++ modules/angular2/test/core/facade/collection_spec.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/modules/angular2/src/core/facade/collection.dart b/modules/angular2/src/core/facade/collection.dart index 1e5bb72628..e58c310be2 100644 --- a/modules/angular2/src/core/facade/collection.dart +++ b/modules/angular2/src/core/facade/collection.dart @@ -182,6 +182,10 @@ class ListWrapper { } static List slice(List l, [int from = 0, int to]) { + //in JS if from > to an empty array is returned + if(to != null && from > to) { + return []; + } return l.sublist(_startOffset(l, from), _endOffset(l, to)); } diff --git a/modules/angular2/test/core/facade/collection_spec.ts b/modules/angular2/test/core/facade/collection_spec.ts index dafdd322fa..bd3d2c3786 100644 --- a/modules/angular2/test/core/facade/collection_spec.ts +++ b/modules/angular2/test/core/facade/collection_spec.ts @@ -62,6 +62,9 @@ export function main() { it('should support negative end', () => { expect(ListWrapper.slice(l, -3, -1)).toEqual([2, 3]); }); + + it('should return empty list if start is greater than end', + () => { expect(ListWrapper.slice(l, 4, 2)).toEqual([]); }); }); describe('indexOf', () => {