From 9415935902f120a9bac0bfce7129725a0db38ed3 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Thu, 8 Oct 2009 09:31:20 +1300 Subject: Switch to on-by-default XSS escaping for rails. This consists of: * String#html_safe! a method to mark a string as 'safe' * ActionView::SafeBuffer a string subclass which escapes anything unsafe which is concatenated to it * Calls to String#html_safe! throughout the rails helpers * a 'raw' helper which lets you concatenate trusted HTML from non-safety-aware sources (e.g. presantized strings in the DB) * New ERB implementation based on erubis which uses a SafeBuffer instead of a String Hat tip to Django for the inspiration. --- actionpack/lib/action_view/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_view/base.rb') diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 664cc3b562..5a4e1bee43 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -260,7 +260,7 @@ module ActionView #:nodoc: @assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) } @controller = controller @helpers = self.class.helpers || Module.new - @_content_for = Hash.new {|h,k| h[k] = "" } + @_content_for = Hash.new {|h,k| h[k] = ActionView::SafeBuffer.new } self.view_paths = view_paths end -- cgit v1.2.3 From 665c7ad29d5614b8f5535d317f1dd2803ddcaa7d Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 8 Oct 2009 10:58:04 -0700 Subject: Fix warning spew for 1.9 --- actionpack/lib/action_view/base.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_view/base.rb') diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 5a4e1bee43..82b419d846 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -239,7 +239,11 @@ module ActionView #:nodoc: name = controller.class.name.gsub(/::/, '__') Subclasses.class_eval do - remove_const(name) if const_defined?(name) + if method(:const_defined?).arity == 1 + remove_const(name) if const_defined?(name) # Ruby 1.8.x + else + remove_const(name) if const_defined?(name, false) # Ruby 1.9.x + end const_set(name, self) end -- cgit v1.2.3