We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/josh/rails.git
Protect body ivar from being clobbered by the mailer template assigns
josh (author)
Sun Sep 28 10:31:45 -0700 2008
commit  28bf2fa03886e3ea7d873375239395b91b8e530e
tree    0d3d6982867a9c054b1f6f45c285a303d8d28cc8
parent  ea609b265ffc30cac00bf09a262027f96964ed6f
...
296
297
298
 
 
 
299
300
301
...
296
297
298
299
300
301
302
303
304
0
@@ -296,6 +296,9 @@ module ActionMailer #:nodoc:
0
     @@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ]
0
     cattr_accessor :default_implicit_parts_order
0
 
0
+ cattr_reader :protected_instance_variables
0
+ @@protected_instance_variables = %w(@body)
0
+
0
     # Specify the BCC addresses for the message
0
     adv_attr_accessor :bcc
0
 
...
273
274
275
 
 
 
 
 
 
 
276
277
278
...
926
927
928
 
 
 
 
 
929
930
931
...
273
274
275
276
277
278
279
280
281
282
283
284
285
...
933
934
935
936
937
938
939
940
941
942
943
0
@@ -273,6 +273,13 @@ class TestMailer < ActionMailer::Base
0
     headers "return-path" => "another@somewhere.test"
0
   end
0
 
0
+ def body_ivar(recipient)
0
+ recipients recipient
0
+ subject "Body as a local variable"
0
+ from "test@example.com"
0
+ body :body => "foo", :bar => "baz"
0
+ end
0
+
0
   class <<self
0
     attr_accessor :received_body
0
   end
0
@@ -926,6 +933,11 @@ EOF
0
     TestMailer.deliver_return_path
0
     assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
0
   end
0
+
0
+ def test_body_is_stored_as_an_ivar
0
+ mail = TestMailer.create_body_ivar(@recipient)
0
+ assert_equal "body: foo\nbar: baz", mail.body
0
+ end
0
 end
0
 
0
 end # uses_mocha
...
296
297
298
299
 
300
301
 
302
303
304
...
296
297
298
 
299
300
 
301
302
303
304
0
@@ -296,9 +296,9 @@ module ActionView #:nodoc:
0
           @assigns.each { |key, value| instance_variable_set("@#{key}", value) }
0
 
0
           if @controller
0
- variables = @controller.instance_variables
0
+ variables = @controller.instance_variable_names
0
             variables -= @controller.protected_instance_variables if @controller.respond_to?(:protected_instance_variables)
0
- variables.each {|name| instance_variable_set(name, @controller.instance_variable_get(name)) }
0
+ variables.each { |name| instance_variable_set(name, @controller.instance_variable_get(name)) }
0
           end
0
 
0
           @assigns_added = true

Comments

    No one has commented yet.