diff --git a/CHANGELOG b/CHANGELOG index cd2983d..1415858 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Prevent Enumerable#eachSlice from entering into an endless loop if passed an argument smaller than 1. Closes #10665. [kangax, Tobie Langel] + * Allow Selector to correctly detect the presence of namespaced attributes. Closes #10987. [Samuel Lebeau, Tobie Langel] * Make Element#absolutize and Element#relativize always return element. Closes #10983. [kangax] diff --git a/src/enumerable.js b/src/enumerable.js index 45ace8e..2c565a1 100644 --- a/src/enumerable.js +++ b/src/enumerable.js @@ -17,6 +17,7 @@ var Enumerable = { eachSlice: function(number, iterator, context) { iterator = iterator ? iterator.bind(context) : Prototype.K; var index = -number, slices = [], array = this.toArray(); + if (number < 1) return array; while ((index += number) < array.length) slices.push(array.slice(index, index+number)); return slices.collect(iterator, context); diff --git a/test/unit/enumerable.html b/test/unit/enumerable.html index 8421eb8..c2e29e4 100644 --- a/test/unit/enumerable.html +++ b/test/unit/enumerable.html @@ -164,6 +164,9 @@ [3, 2, 1, 11, 7, 5, 19, 17, 13, 31, 29, 23, 43, 41, 37, 59, 53, 47, 71, 67, 61, 83, 79, 73, 97, 89], Fixtures.Primes.eachSlice( 3, function(slice){ return slice.reverse() }).flatten() ); + assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(-10)); + assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(0)); + assertNotIdentical(Fixtures.Basic, Fixtures.Basic.eachSlice(0)); }}, testEachWithIndex: function() {with(this) {