Skip to content

Commit

Permalink
prototype: Prevent Enumerable#eachSlice from entering into an endless…
Browse files Browse the repository at this point in the history
… loop if passed an argument smaller than 1. Closes #10665.
  • Loading branch information
tobie committed Feb 3, 2008
1 parent f4d6835 commit d770a6c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/enumerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions test/unit/enumerable.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ <h1>Prototype Unit test file</h1>
[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) {
Expand Down

0 comments on commit d770a6c

Please sign in to comment.