'only' filter option leaks into other controllers
Reported by Paul Carey | May 23rd, 2008 @ 06:23 PM | in 0.9.4
Maybe this is expected, but the following was certainly a surprise for me. Given the code below, hitting /c2 does not result in "foo" being printed. If the only option is removed from the before filter in c1.rb, accessing /c2 does then result in "foo" being printed.
File: /app/controllers/application.rb
class Application < Merb::Controller
before :print_foo
end
File: /app/controllers/c1.rb
class C1 < Application
before :print_foo, :only => :meh
def index; render; end
def meh; "meh"; end
end
File: /app/controllers/c2.rb
class C2 < Application
def index; render; end
end
File: /app/helpers/global_helpers.rb
module Merb
module GlobalHelpers
def print_foo; Merb.logger.info("foo"); end
end
end
Comments and changes to this ticket
-
Michael Klishin (antares) May 24th, 2008 @ 04:31 AM
- → Milestone changed from to 0.9.4
- → State changed from new to open
Looks pretty nasty, thanks for reporting!
-
Michael Klishin (antares) June 2nd, 2008 @ 09:51 AM
- → Assigned user changed from to Michael Klishin (antares)
-
Michael D. Ivey (ivey) June 12th, 2008 @ 01:21 AM
- → Assigned user changed from Michael Klishin (antares) to Yehuda Katz (wycats)
wycats is working on this, as I understand it
-
Michael Klishin (antares) August 2nd, 2008 @ 06:45 PM
- → Tag changed from to controller merb-core
- → Milestone changed from 0.9.4 to 0.9.8
-
-
Carl Lerche August 7th, 2008 @ 05:53 AM
I probably should have elaborated a bit (and there is no edit comment link?)
The bug is from the fact that classattributeaccessor does shallow copies of the inherited class attribute. In AbstractController, when a filter is modified, it replaces the relevant information in the nested array (which is not cloned throughout the inheritance of controllers).
This means that any change to a filter will bleed to other controllers.
-
Michael Klishin (antares) August 7th, 2008 @ 06:36 AM
- → Milestone changed from 0.9.8 to 0.9.4
- → State changed from open to resolved
- → Assigned user changed from Yehuda Katz (wycats) to Michael Klishin (antares)
Applied with slight update of spec example. Thank you.
-
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
