diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-11-06 01:07:10 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-11-06 01:07:10 +0530 |
commit | 215122890b8cecca3809d981accd84bfd5486196 (patch) | |
tree | 11dd8368e2674342098af21136893bee491c44ff | |
parent | 94f3a94b0b66e576287f48627282dc1a21bf51a7 (diff) | |
parent | 32089cbcc9ca3fb935f783e7a7ef2b60b7d43006 (diff) | |
download | rails-215122890b8cecca3809d981accd84bfd5486196.tar.gz rails-215122890b8cecca3809d981accd84bfd5486196.tar.bz2 rails-215122890b8cecca3809d981accd84bfd5486196.zip |
Merge commit 'mainstream/master'
-rw-r--r-- | actionpack/CHANGELOG | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/base.rb | 12 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/date_helper.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_tag_helper.rb | 14 | ||||
-rw-r--r-- | actionpack/test/template/date_helper_test.rb | 40 | ||||
-rw-r--r-- | actionpack/test/template/form_tag_helper_test.rb | 35 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/pooled_connections_test.rb | 8 | ||||
-rw-r--r-- | activesupport/lib/active_support/testing/performance.rb | 2 |
9 files changed, 103 insertions, 18 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 17fada156d..3ce6522535 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,9 @@ *2.2.1 [RC2 or 2.2 final]* +* Fixed that FormTagHelper generated illegal html if name contained square brackets #1238 [Vladimir Dobriakov] + +* Fix regression bug that made date_select and datetime_select raise a Null Pointer Exception when a nil date/datetime was passed and only month and year were displayed #1289 [Bernardo Padua/Tor Erik] + * Simplified the logging format for parameters (don't include controller, action, and format as duplicates) [DHH] * Remove the logging of the Session ID when the session store is CookieStore [DHH] diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 087fdc35cd..3a7f6c0f3c 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -278,12 +278,6 @@ module ActionController #:nodoc: @@consider_all_requests_local = true cattr_accessor :consider_all_requests_local - # Enable or disable the collection of failure information for RoutingErrors. - # This information can be extremely useful when tweaking custom routes, but is - # pointless once routes have been tested and verified. - @@debug_routes = true - cattr_accessor :debug_routes - # Indicates whether to allow concurrent action processing. Your # controller actions and any other code they call must also behave well # when called from concurrent threads. Turned off by default. @@ -1070,7 +1064,7 @@ module ActionController #:nodoc: status = 302 end - response.redirected_to= options + response.redirected_to = options logger.info("Redirected to #{options}") if logger && logger.info? case options @@ -1244,8 +1238,8 @@ module ActionController #:nodoc: end def log_processing_for_parameters - parameters = respond_to?(:filter_parameters) ? filter_parameters(params) : params - parameters = parameters.except(:controller, :action, :format) + parameters = respond_to?(:filter_parameters) ? filter_parameters(params) : params.dup + parameters = parameters.except!(:controller, :action, :format, :_method) logger.info " Parameters: #{parameters.inspect}" end diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index d4d2c6ef53..919c937444 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -539,7 +539,7 @@ module ActionView # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are # valid (otherwise it could be 31 and february wouldn't be a valid date) - if @options[:discard_day] && !@options[:discard_month] + if @datetime && @options[:discard_day] && !@options[:discard_month] @datetime = @datetime.change(:day => 1) end @@ -567,7 +567,7 @@ module ActionView # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are # valid (otherwise it could be 31 and february wouldn't be a valid date) - if @options[:discard_day] && !@options[:discard_month] + if @datetime && @options[:discard_day] && !@options[:discard_month] @datetime = @datetime.change(:day => 1) end end diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 7492348c50..4646bc118b 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -78,7 +78,7 @@ module ActionView # # <option>Paris</option><option>Rome</option></select> def select_tag(name, option_tags = nil, options = {}) html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name - content_tag :select, option_tags, { "name" => html_name, "id" => name }.update(options.stringify_keys) + content_tag :select, option_tags, { "name" => html_name, "id" => sanitize_to_id(name) }.update(options.stringify_keys) end # Creates a standard text field; use these text fields to input smaller chunks of text like a username @@ -112,7 +112,7 @@ module ActionView # text_field_tag 'ip', '0.0.0.0', :maxlength => 15, :size => 20, :class => "ip-input" # # => <input class="ip-input" id="ip" maxlength="15" name="ip" size="20" type="text" value="0.0.0.0" /> def text_field_tag(name, value = nil, options = {}) - tag :input, { "type" => "text", "name" => name, "id" => name, "value" => value }.update(options.stringify_keys) + tag :input, { "type" => "text", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys) end # Creates a label field @@ -130,7 +130,7 @@ module ActionView # label_tag 'name', nil, :class => 'small_label' # # => <label for="name" class="small_label">Name</label> def label_tag(name, text = nil, options = {}) - content_tag :label, text || name.to_s.humanize, { "for" => name }.update(options.stringify_keys) + content_tag :label, text || name.to_s.humanize, { "for" => sanitize_to_id(name) }.update(options.stringify_keys) end # Creates a hidden form input field used to transmit data that would be lost due to HTTP's statelessness or @@ -282,7 +282,7 @@ module ActionView # check_box_tag 'eula', 'accepted', false, :disabled => true # # => <input disabled="disabled" id="eula" name="eula" type="checkbox" value="accepted" /> def check_box_tag(name, value = "1", checked = false, options = {}) - html_options = { "type" => "checkbox", "name" => name, "id" => name, "value" => value }.update(options.stringify_keys) + html_options = { "type" => "checkbox", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys) html_options["checked"] = "checked" if checked tag :input, html_options end @@ -470,6 +470,12 @@ module ActionView tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token) end end + + # see http://www.w3.org/TR/html4/types.html#type-name + def sanitize_to_id(name) + name.to_s.gsub(']','').gsub(/[^-a-zA-Z0-9:.]/, "_") + end + end end end diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 1a645bccc6..49ba140c23 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1149,6 +1149,46 @@ class DateHelperTest < ActionView::TestCase assert_dom_equal expected, date_select("post", "written_on", :include_blank => true) end + + def test_date_select_with_nil_and_blank_and_order + @post = Post.new + + start_year = Time.now.year-5 + end_year = Time.now.year+5 + + expected = '<input name="post[written_on(3i)]" type="hidden" id="post_written_on_3i"/>' + "\n" + expected << %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected << "<option value=\"\"></option>\n" + start_year.upto(end_year) { |i| expected << %(<option value="#{i}">#{i}</option>\n) } + expected << "</select>\n" + + expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n} + expected << "<option value=\"\"></option>\n" + 1.upto(12) { |i| expected << %(<option value="#{i}">#{Date::MONTHNAMES[i]}</option>\n) } + expected << "</select>\n" + + assert_dom_equal expected, date_select("post", "written_on", :order=>[:year, :month], :include_blank=>true) + end + + def test_date_select_with_nil_and_blank_and_order + @post = Post.new + + start_year = Time.now.year-5 + end_year = Time.now.year+5 + + expected = '<input name="post[written_on(3i)]" type="hidden" id="post_written_on_3i"/>' + "\n" + expected << %{<select id="post_written_on_1i" name="post[written_on(1i)]">\n} + expected << "<option value=\"\"></option>\n" + start_year.upto(end_year) { |i| expected << %(<option value="#{i}">#{i}</option>\n) } + expected << "</select>\n" + + expected << %{<select id="post_written_on_2i" name="post[written_on(2i)]">\n} + expected << "<option value=\"\"></option>\n" + 1.upto(12) { |i| expected << %(<option value="#{i}">#{Date::MONTHNAMES[i]}</option>\n) } + expected << "</select>\n" + + assert_dom_equal expected, date_select("post", "written_on", :order=>[:year, :month], :include_blank=>true) + end def test_date_select_cant_override_discard_hour @post = Post.new diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 1849a61f2f..de82647813 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -12,12 +12,19 @@ class FormTagHelperTest < ActionView::TestCase @controller = @controller.new end + VALID_HTML_ID = /^[A-Za-z][-_:.A-Za-z0-9]*$/ # see http://www.w3.org/TR/html4/types.html#type-name + def test_check_box_tag actual = check_box_tag "admin" expected = %(<input id="admin" name="admin" type="checkbox" value="1" />) assert_dom_equal expected, actual end + def test_check_box_tag_id_sanitized + label_elem = root_elem(check_box_tag("project[2][admin]")) + assert_match VALID_HTML_ID, label_elem['id'] + end + def test_form_tag actual = form_tag expected = %(<form action="http://www.example.com" method="post">) @@ -64,6 +71,11 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_hidden_field_tag_id_sanitized + input_elem = root_elem(hidden_field_tag("item[][title]")) + assert_match VALID_HTML_ID, input_elem['id'] + end + def test_file_field_tag assert_dom_equal "<input name=\"picsplz\" type=\"file\" id=\"picsplz\" />", file_field_tag("picsplz") end @@ -118,6 +130,11 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_select_tag_id_sanitized + input_elem = root_elem(select_tag("project[1]people", "<option>david</option>")) + assert_match VALID_HTML_ID, input_elem['id'] + end + def test_text_area_tag_size_string actual = text_area_tag "body", "hello world", "size" => "20x40" expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>) @@ -184,6 +201,11 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_text_field_tag_id_sanitized + input_elem = root_elem(text_field_tag("item[][title]")) + assert_match VALID_HTML_ID, input_elem['id'] + end + def test_label_tag_without_text actual = label_tag "title" expected = %(<label for="title">Title</label>) @@ -208,11 +230,16 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_label_tag_id_sanitized + label_elem = root_elem(label_tag("item[title]")) + assert_match VALID_HTML_ID, label_elem['for'] + end + def test_boolean_optios assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes") assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil) assert_dom_equal %(<select id="people" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => true) - assert_dom_equal %(<select id="people[]" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people[]", "<option>david</option>", :multiple => true) + assert_dom_equal %(<select id="people_" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people[]", "<option>david</option>", :multiple => true) assert_dom_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => nil) end @@ -283,4 +310,10 @@ class FormTagHelperTest < ActionView::TestCase def protect_against_forgery? false end + + private + + def root_elem(rendered_content) + HTML::Document.new(rendered_content).root.children[0] + end end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 432c341e6c..3016c329bd 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -324,7 +324,7 @@ module ActiveRecord # Returns true if a connection that's accessible to this class has # already been opened. def connected?(klass) - retrieve_connection_pool(klass).connected? + conn = retrieve_connection_pool(klass) ? conn.connected? : false end # Remove the connection for this class. This will close the active diff --git a/activerecord/test/cases/pooled_connections_test.rb b/activerecord/test/cases/pooled_connections_test.rb index 078ca1d679..3e8c617a89 100644 --- a/activerecord/test/cases/pooled_connections_test.rb +++ b/activerecord/test/cases/pooled_connections_test.rb @@ -73,6 +73,14 @@ class PooledConnectionsTest < ActiveRecord::TestCase assert ActiveRecord::ConnectionAdapters::AbstractAdapter === conn conn_pool.checkin(conn) end + + def test_undefined_connection_returns_false + old_handler = ActiveRecord::Base.connection_handler + ActiveRecord::Base.connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new + assert_equal false, ActiveRecord::Base.connected? + ensure + ActiveRecord::Base.connection_handler = old_handler + end end unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name class AllowConcurrencyDeprecatedTest < ActiveRecord::TestCase diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index f996c40793..bd136c2596 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -124,7 +124,7 @@ module ActiveSupport def environment unless defined? @env - app = "#{$1}.#{$2}" if `git branch -v` =~ /^\* (\S+)\s+(\S+)/ + app = "#{$1}.#{$2}" if File.directory?('.git') && `git branch -v` =~ /^\* (\S+)\s+(\S+)/ rails = Rails::VERSION::STRING if File.directory?('vendor/rails/.git') |