Permalink
Browse files

Fixes an issue when creating a date select with too many options.

  • Loading branch information...
1 parent a9d27c0 commit 9e615634745dc81598e7b880d52411338d3a7a93 @dlt committed Mar 27, 2011
Showing with 11 additions and 0 deletions.
  1. +6 −0 actionpack/lib/action_view/helpers/date_helper.rb
  2. +5 −0 actionpack/test/template/date_helper_test.rb
@@ -810,6 +810,12 @@ def build_options(selected, options = {})
step = options.delete(:step) || 1
options.reverse_merge!({:leading_zeros => true})
leading_zeros = options.delete(:leading_zeros)
+ limit = (stop - start).abs
+ max_options = 1000
+
+ if limit / step.abs > max_options
+ raise ArgumentError, "Cannot build too many options for select."
+ end
select_options = []
start.step(stop, step) do |i|
@@ -668,6 +668,11 @@ def test_select_date_with_order
assert_dom_equal expected, select_date(Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005, :prefix => "date[first]", :order => [:month, :day, :year])
end
+ def test_select_date_with_too_big_range_between_start_year_and_end_year
+ assert_raise(ArgumentError) { select_date(Time.mktime(2003, 8, 16), :start_year => 2000, :end_year => 20000.years, :prefix => "date[first]", :order => [:month, :day, :year]) }
+ assert_raise(ArgumentError) { select_date(Time.mktime(2003, 8, 16), :start_year => Date.today.year - 100.years, :end_year => 2000, :prefix => "date[first]", :order => [:month, :day, :year]) }
+ end
+
def test_select_date_with_incomplete_order
# Since the order is incomplete nothing will be shown
expected = %(<input id="date_first_year" name="date[first][year]" type="hidden" value="2003" />\n)

0 comments on commit 9e61563

Please sign in to comment.