Permalink
Browse files

validate range of arguments to Collection#create

  • Loading branch information...
1 parent 7288d61 commit 4d92d1b8dfc0d50cb9ee013e0051f524f0015641 Jonah Williams committed with Mar 22, 2011
Showing with 10 additions and 4 deletions.
  1. +3 −1 lib/will_paginate/collection.rb
  2. +7 −3 test/collection_test.rb
@@ -47,9 +47,11 @@ class Collection < Array
def initialize(page, per_page, total = nil)
@current_page = page.to_i
raise InvalidPage.new(page, @current_page) if @current_page < 1
+ raise InvalidPage.new(page, @current_page) if @current_page > 9223372036854775807
@per_page = per_page.to_i
raise ArgumentError, "`per_page` setting cannot be less than 1 (#{@per_page} given)" if @per_page < 1
-
+ raise ArgumentError, "`per_page` setting cannot be greater than BIGINT" if @per_page > 9223372036854775807
+
self.total_entries = total if total
end
@@ -112,15 +112,19 @@ def test_guessing_total_count
end
def test_invalid_page
- bad_inputs = [0, -1, nil, '', 'Schnitzel']
+ bad_inputs = [0, -1, nil, '', 9223372036854775808, 'Schnitzel']
bad_inputs.each do |bad|
assert_raise(WillPaginate::InvalidPage) { create bad }
end
end
- def test_invalid_per_page_setting
- assert_raise(ArgumentError) { create(1, -1) }
+ def test_invalid_per_page
+ bad_inputs = [0, -1, 9223372036854775808, 'Schnitzel']
+
+ bad_inputs.each do |bad|
+ assert_raise(ArgumentError) { create(1, bad) }
+ end
end
def test_page_count_was_removed

0 comments on commit 4d92d1b

Please sign in to comment.