From 7b73913701ff41981d166ca457e41690aac3bce3 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Mon, 20 Feb 2012 15:41:17 -0800 Subject: [PATCH 1/9] fix output safety issue with select options --- .../lib/action_view/helpers/form_options_helper.rb | 6 +++--- actionpack/test/template/form_options_helper_test.rb | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index e00ac8f3f2db4..f64d3907a2330 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -616,13 +616,13 @@ def to_time_zone_select_tag(priority_zones, options, html_options) private def add_options(option_tags, options, value = nil) if options[:include_blank] - option_tags = "\n" + option_tags + option_tags = content_tag('option', options[:include_blank].kind_of?(String) ? options[:include_blank] : nil, :value => '') + "\n" + option_tags end if value.blank? && options[:prompt] prompt = options[:prompt].kind_of?(String) ? options[:prompt] : I18n.translate('helpers.select.prompt', :default => 'Please select') - option_tags = "\n" + option_tags + option_tags = content_tag('option', prompt, :value => '') + "\n" + option_tags end - option_tags.html_safe + option_tags end def select_content_tag(option_tags, options, html_options) diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 62ab208c2e8a6..5b19bcf0f9555 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -495,7 +495,7 @@ def @post.to_param; 108; end def test_select_under_fields_for_with_string_and_given_prompt @post = Post.new - options = "" + options = "".html_safe output_buffer = fields_for :post, @post do |f| concat f.select(:category, options, :prompt => 'The prompt') @@ -651,6 +651,13 @@ def test_select_with_index_option ) end + def test_select_escapes_options + assert_dom_equal( + '', + select('post', 'title', '') + ) + end + def test_select_with_selected_nil @post = Post.new @post.category = "" From 621d2199599e9a3154ce6f6e81385bf574030f15 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 13 Feb 2012 17:54:58 +0900 Subject: [PATCH 2/9] add AS::SafeBuffer#clone_empty --- .../lib/active_support/core_ext/string/output_safety.rb | 6 ++++++ activesupport/test/safe_buffer_test.rb | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index c6d861d124e65..5b39fd6a6ace7 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -119,6 +119,12 @@ def initialize_copy(other) @dirty = other.dirty? end + def clone_empty + new_safe_buffer = self[0, 0] + new_safe_buffer.instance_variable_set(:@dirty, @dirty) + new_safe_buffer + end + def concat(value) if dirty? || value.html_safe? super(value) diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index db9159b289518..20731218cf368 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -116,4 +116,13 @@ def test_titleize assert_not_nil dirty assert !dirty end + + test "clone_empty returns an empty buffer" do + assert_equal '', ActiveSupport::SafeBuffer.new('foo').clone_empty + end + + test "clone_empty keeps the original dirtyness" do + assert @buffer.clone_empty.html_safe? + assert !@buffer.gsub!('', '').clone_empty.html_safe? + end end From 42fabd23669605da1ada3e3d03befde9efd39b27 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 13 Feb 2012 17:57:05 +0900 Subject: [PATCH 3/9] use AS::SafeBuffer#clone_empty for flushing the output_buffer --- actionpack/lib/action_view/helpers/capture_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 8abd85c3a3ca7..370bbaf623c47 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -194,7 +194,7 @@ def with_output_buffer(buf = nil) #:nodoc: def flush_output_buffer #:nodoc: if output_buffer && !output_buffer.empty? response.body_parts << output_buffer - self.output_buffer = output_buffer[0,0] + self.output_buffer = output_buffer.respond_to?(:clone_empty) ? output_buffer.clone_empty : output_buffer[0, 0] nil end end From dfa33fa3da2e8495f5647c553704297cdc857917 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 13 Feb 2012 17:58:01 +0900 Subject: [PATCH 4/9] delete vulnerable AS::SafeBuffer#[] --- .../lib/active_support/core_ext/string/output_safety.rb | 6 ------ activesupport/test/safe_buffer_test.rb | 6 ------ 2 files changed, 12 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 5b39fd6a6ace7..e3fa528efb419 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -98,12 +98,6 @@ def initialize end end - def[](*args) - new_safe_buffer = super - new_safe_buffer.instance_eval { @dirty = false } - new_safe_buffer - end - def safe_concat(value) raise SafeConcatError if dirty? original_concat(value) diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index 20731218cf368..e731f1c2e7cd1 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -111,12 +111,6 @@ def test_titleize assert_kind_of NilClass, @buffer.slice("chipchop") end - test "Should initialize @dirty to false for new instance when sliced" do - dirty = @buffer[0,0].send(:dirty?) - assert_not_nil dirty - assert !dirty - end - test "clone_empty returns an empty buffer" do assert_equal '', ActiveSupport::SafeBuffer.new('foo').clone_empty end From 4bcd437f760cfaf310fece0fe36abe55bccba42b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 22 Feb 2012 12:03:13 -0800 Subject: [PATCH 5/9] updating RAILS_VERSION --- RAILS_VERSION | 2 +- actionmailer/lib/action_mailer/version.rb | 4 ++-- actionpack/lib/action_pack/version.rb | 4 ++-- activemodel/lib/active_model/version.rb | 4 ++-- activerecord/lib/active_record/version.rb | 4 ++-- activeresource/lib/active_resource/version.rb | 4 ++-- activesupport/lib/active_support/version.rb | 4 ++-- railties/lib/rails/version.rb | 4 ++-- version.rb | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/RAILS_VERSION b/RAILS_VERSION index e4604e3afd0dd..183633372e233 100644 --- a/RAILS_VERSION +++ b/RAILS_VERSION @@ -1 +1 @@ -3.2.1 +3.2.2.rc1 diff --git a/actionmailer/lib/action_mailer/version.rb b/actionmailer/lib/action_mailer/version.rb index 5817ed363d71a..fa416a03607e3 100644 --- a/actionmailer/lib/action_mailer/version.rb +++ b/actionmailer/lib/action_mailer/version.rb @@ -2,8 +2,8 @@ module ActionMailer module VERSION #:nodoc: MAJOR = 3 MINOR = 2 - TINY = 1 - PRE = nil + TINY = 2 + PRE = "rc1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/actionpack/lib/action_pack/version.rb b/actionpack/lib/action_pack/version.rb index a6041385f8f4f..1f501a3c52b29 100644 --- a/actionpack/lib/action_pack/version.rb +++ b/actionpack/lib/action_pack/version.rb @@ -2,8 +2,8 @@ module ActionPack module VERSION #:nodoc: MAJOR = 3 MINOR = 2 - TINY = 1 - PRE = nil + TINY = 2 + PRE = "rc1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/activemodel/lib/active_model/version.rb b/activemodel/lib/active_model/version.rb index 91b566c4344ec..c7983a89f3eec 100644 --- a/activemodel/lib/active_model/version.rb +++ b/activemodel/lib/active_model/version.rb @@ -2,8 +2,8 @@ module ActiveModel module VERSION #:nodoc: MAJOR = 3 MINOR = 2 - TINY = 1 - PRE = nil + TINY = 2 + PRE = "rc1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/activerecord/lib/active_record/version.rb b/activerecord/lib/active_record/version.rb index 92e3b362c83a3..d34726de44000 100644 --- a/activerecord/lib/active_record/version.rb +++ b/activerecord/lib/active_record/version.rb @@ -2,8 +2,8 @@ module ActiveRecord module VERSION #:nodoc: MAJOR = 3 MINOR = 2 - TINY = 1 - PRE = nil + TINY = 2 + PRE = "rc1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/activeresource/lib/active_resource/version.rb b/activeresource/lib/active_resource/version.rb index e9561df2859a3..a7c7776a6b701 100644 --- a/activeresource/lib/active_resource/version.rb +++ b/activeresource/lib/active_resource/version.rb @@ -2,8 +2,8 @@ module ActiveResource module VERSION #:nodoc: MAJOR = 3 MINOR = 2 - TINY = 1 - PRE = nil + TINY = 2 + PRE = "rc1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/activesupport/lib/active_support/version.rb b/activesupport/lib/active_support/version.rb index ef2c69e69559e..3ba71473c3e08 100644 --- a/activesupport/lib/active_support/version.rb +++ b/activesupport/lib/active_support/version.rb @@ -2,8 +2,8 @@ module ActiveSupport module VERSION #:nodoc: MAJOR = 3 MINOR = 2 - TINY = 1 - PRE = nil + TINY = 2 + PRE = "rc1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb index 048bd6d35b6ba..a5719a84e585c 100644 --- a/railties/lib/rails/version.rb +++ b/railties/lib/rails/version.rb @@ -2,8 +2,8 @@ module Rails module VERSION #:nodoc: MAJOR = 3 MINOR = 2 - TINY = 1 - PRE = nil + TINY = 2 + PRE = "rc1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/version.rb b/version.rb index 048bd6d35b6ba..a5719a84e585c 100644 --- a/version.rb +++ b/version.rb @@ -2,8 +2,8 @@ module Rails module VERSION #:nodoc: MAJOR = 3 MINOR = 2 - TINY = 1 - PRE = nil + TINY = 2 + PRE = "rc1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end From 93f1667e91c7fa6d2136bcd64f8c8a1231da4a7f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 22 Feb 2012 15:57:15 -0800 Subject: [PATCH 6/9] Merge pull request #5084 from johndouthat/patch-1 Remove reference to rails_legacy_mapper, which isn't compatible with 3.2... --- actionpack/lib/action_dispatch/routing/route_set.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 33eb7b0746b93..a78e1e13b0236 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -267,8 +267,7 @@ def prepend(&block) def eval_block(block) if block.arity == 1 raise "You are using the old router DSL which has been removed in Rails 3.1. " << - "Please check how to update your routes file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/ " << - "or add the rails_legacy_mapper gem to your Gemfile" + "Please check how to update your routes file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/" end mapper = Mapper.new(self) if default_scope From ecff25cda6917a07c7bcb4ed0865c75d16164306 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 13 Feb 2012 11:01:02 -0800 Subject: [PATCH 7/9] Merge pull request #4834 from sskirby/fix_usage_of_psql_in_db_test_prepare Fix usage of psql in db:test:prepare --- activerecord/lib/active_record/railties/databases.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 2df83514bd5eb..b94df4262a393 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -424,7 +424,7 @@ db_namespace = namespace :db do end when /postgresql/ set_psql_env(abcs[env]) - `psql -f "#{filename}" #{abcs[env]['database']} #{abcs[env]['template']}` + `psql -f "#{filename}" #{abcs[env]['database']}` when /sqlite/ dbfile = abcs[env]['database'] `sqlite3 #{dbfile} < "#{filename}"` From 55ac1b9d889ddfdeaa3d6eb9389d3cc7695b8e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 29 Feb 2012 22:30:51 +0100 Subject: [PATCH 8/9] Ensure [] respects the status of the buffer. --- .../core_ext/string/output_safety.rb | 30 +++++++++------- activesupport/test/safe_buffer_test.rb | 36 ++++++++++++++++--- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index e3fa528efb419..4089b02d4503d 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -98,19 +98,31 @@ def initialize end end + def [](*args) + return super if args.size < 2 + + if html_safe? + new_safe_buffer = super + new_safe_buffer.instance_eval { @html_safe = true } + new_safe_buffer + else + to_str[*args] + end + end + def safe_concat(value) - raise SafeConcatError if dirty? + raise SafeConcatError unless html_safe? original_concat(value) end def initialize(*) - @dirty = false + @html_safe = true super end def initialize_copy(other) super - @dirty = other.dirty? + @html_safe = other.html_safe? end def clone_empty @@ -120,7 +132,7 @@ def clone_empty end def concat(value) - if dirty? || value.html_safe? + if !html_safe? || value.html_safe? super(value) else super(ERB::Util.h(value)) @@ -133,7 +145,7 @@ def +(other) end def html_safe? - !dirty? + defined?(@html_safe) && @html_safe end def to_s @@ -161,18 +173,12 @@ def #{unsafe_method}(*args, &block) # def capitalize(*args, &block) end # end def #{unsafe_method}!(*args) # def capitalize!(*args) - @dirty = true # @dirty = true + @html_safe = false # @html_safe = false super # super end # end EOT end end - - protected - - def dirty? - @dirty - end end end diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index e731f1c2e7cd1..25c95f2a2f365 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -89,25 +89,32 @@ def test_titleize assert_equal "hello<>", clean + @buffer end - test "Should concat as a normal string when dirty" do + test "Should concat as a normal string when safe" do clean = "hello".html_safe @buffer.gsub!('', '<>') assert_equal "<>hello", @buffer + clean end - test "Should preserve dirty? status on copy" do + test "Should preserve html_safe? status on copy" do @buffer.gsub!('', '<>') assert !@buffer.dup.html_safe? end - test "Should raise an error when safe_concat is called on dirty buffers" do + test "Should return safe buffer when added with another safe buffer" do + clean = "') + + # calling gsub! makes the dirty flag true + assert !x.html_safe?, "should not be safe" + + # getting a slice of it + y = x[0..-1] + + # should still be unsafe + assert !y.html_safe?, "should not be safe" + end end From 01b470f526922ad3fc5562a237d11d45347befa9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 1 Mar 2012 09:16:28 -0800 Subject: [PATCH 9/9] bumping to 3.2.2 --- RAILS_VERSION | 2 +- actionmailer/lib/action_mailer/version.rb | 2 +- actionpack/lib/action_pack/version.rb | 2 +- activemodel/lib/active_model/version.rb | 2 +- activerecord/lib/active_record/version.rb | 2 +- activeresource/lib/active_resource/version.rb | 2 +- activesupport/lib/active_support/version.rb | 2 +- railties/lib/rails/version.rb | 2 +- version.rb | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/RAILS_VERSION b/RAILS_VERSION index 183633372e233..be94e6f53db6b 100644 --- a/RAILS_VERSION +++ b/RAILS_VERSION @@ -1 +1 @@ -3.2.2.rc1 +3.2.2 diff --git a/actionmailer/lib/action_mailer/version.rb b/actionmailer/lib/action_mailer/version.rb index fa416a03607e3..1013180a3824a 100644 --- a/actionmailer/lib/action_mailer/version.rb +++ b/actionmailer/lib/action_mailer/version.rb @@ -3,7 +3,7 @@ module VERSION #:nodoc: MAJOR = 3 MINOR = 2 TINY = 2 - PRE = "rc1" + PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/actionpack/lib/action_pack/version.rb b/actionpack/lib/action_pack/version.rb index 1f501a3c52b29..edc0cc97a7619 100644 --- a/actionpack/lib/action_pack/version.rb +++ b/actionpack/lib/action_pack/version.rb @@ -3,7 +3,7 @@ module VERSION #:nodoc: MAJOR = 3 MINOR = 2 TINY = 2 - PRE = "rc1" + PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/activemodel/lib/active_model/version.rb b/activemodel/lib/active_model/version.rb index c7983a89f3eec..3d2cbf0de4d1f 100644 --- a/activemodel/lib/active_model/version.rb +++ b/activemodel/lib/active_model/version.rb @@ -3,7 +3,7 @@ module VERSION #:nodoc: MAJOR = 3 MINOR = 2 TINY = 2 - PRE = "rc1" + PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/activerecord/lib/active_record/version.rb b/activerecord/lib/active_record/version.rb index d34726de44000..d776082260aac 100644 --- a/activerecord/lib/active_record/version.rb +++ b/activerecord/lib/active_record/version.rb @@ -3,7 +3,7 @@ module VERSION #:nodoc: MAJOR = 3 MINOR = 2 TINY = 2 - PRE = "rc1" + PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/activeresource/lib/active_resource/version.rb b/activeresource/lib/active_resource/version.rb index a7c7776a6b701..3c316943ff91e 100644 --- a/activeresource/lib/active_resource/version.rb +++ b/activeresource/lib/active_resource/version.rb @@ -3,7 +3,7 @@ module VERSION #:nodoc: MAJOR = 3 MINOR = 2 TINY = 2 - PRE = "rc1" + PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/activesupport/lib/active_support/version.rb b/activesupport/lib/active_support/version.rb index 3ba71473c3e08..597099eef37c8 100644 --- a/activesupport/lib/active_support/version.rb +++ b/activesupport/lib/active_support/version.rb @@ -3,7 +3,7 @@ module VERSION #:nodoc: MAJOR = 3 MINOR = 2 TINY = 2 - PRE = "rc1" + PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb index a5719a84e585c..154dd3d25d04a 100644 --- a/railties/lib/rails/version.rb +++ b/railties/lib/rails/version.rb @@ -3,7 +3,7 @@ module VERSION #:nodoc: MAJOR = 3 MINOR = 2 TINY = 2 - PRE = "rc1" + PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end diff --git a/version.rb b/version.rb index a5719a84e585c..154dd3d25d04a 100644 --- a/version.rb +++ b/version.rb @@ -3,7 +3,7 @@ module VERSION #:nodoc: MAJOR = 3 MINOR = 2 TINY = 2 - PRE = "rc1" + PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end