Move ActionController::Routing.optimise_named_routes to ActionController::Base.optimise_named_routes. Now you can set it in the config.

ActionController::Routing::DynamicSegment#interpolation_chunk should call #to_s on all values before calling URI.escape.  [Rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7724 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Rick Olson 2007-10-03 05:47:41 +00:00
parent b4ec9904c6
commit 904df818d6
6 changed files with 28 additions and 17 deletions

View File

@ -1,5 +1,11 @@
*SVN* *SVN*
* Move ActionController::Routing.optimise_named_routes to ActionController::Base.optimise_named_routes. Now you can set it in the config. [Rick]
config.action_controller.optimise_named_routes = false
* ActionController::Routing::DynamicSegment#interpolation_chunk should call #to_s on all values before calling URI.escape. [Rick]
* Only accept session ids from cookies, prevents session fixation attacks. [bradediger] * Only accept session ids from cookies, prevents session fixation attacks. [bradediger]
*2.0.0 [Preview Release]* (September 29th, 2007) [Includes duplicates of changes from 1.12.2 - 1.13.3] *2.0.0 [Preview Release]* (September 29th, 2007) [Includes duplicates of changes from 1.12.2 - 1.13.3]

View File

@ -329,7 +329,12 @@ module ActionController #:nodoc:
# Sets the token parameter name for RequestForgery. Calling #protect_from_forgery sets it to :authenticity_token by default # Sets the token parameter name for RequestForgery. Calling #protect_from_forgery sets it to :authenticity_token by default
cattr_accessor :request_forgery_protection_token cattr_accessor :request_forgery_protection_token
# Indicates whether or not optimise the generated named
# route helper methods
cattr_accessor :optimise_named_routes
self.optimise_named_routes = true
# Controls whether request forgergy protection is turned on or not. Turned off by default only in test mode. # Controls whether request forgergy protection is turned on or not. Turned off by default only in test mode.
class_inheritable_accessor :allow_forgery_protection class_inheritable_accessor :allow_forgery_protection
self.allow_forgery_protection = true self.allow_forgery_protection = true

View File

@ -76,7 +76,7 @@ module ActionController
# install the named routes in this session instance. # install the named routes in this session instance.
# But we have to disable the optimisation code so that we can # But we have to disable the optimisation code so that we can
# generate routes without @request being initialized # generate routes without @request being initialized
Routing.optimise_named_routes=false Base.optimise_named_routes=false
Routing::Routes.reload! Routing::Routes.reload!
klass = class<<self; self; end klass = class<<self; self; end
Routing::Routes.install_helpers(klass) Routing::Routes.install_helpers(klass)

View File

@ -256,11 +256,6 @@ module ActionController
mattr_accessor :controller_paths mattr_accessor :controller_paths
self.controller_paths = [] self.controller_paths = []
# Indicates whether or not optimise the generated named
# route helper methods
mattr_accessor :optimise_named_routes
self.optimise_named_routes = true
# A helper module to hold URL related helpers. # A helper module to hold URL related helpers.
module Helpers module Helpers
include PolymorphicRoutes include PolymorphicRoutes
@ -342,7 +337,7 @@ module ActionController
# Indicates whether the routes should be optimised with the string interpolation # Indicates whether the routes should be optimised with the string interpolation
# version of the named routes methods. # version of the named routes methods.
def optimise? def optimise?
@optimise && ActionController::Routing::optimise_named_routes @optimise && ActionController::Base::optimise_named_routes
end end
def segment_keys def segment_keys
@ -718,8 +713,8 @@ module ActionController
s << "\n#{expiry_statement}" s << "\n#{expiry_statement}"
end end
def interpolation_chunk(value_code = "#{local_name}.to_s") def interpolation_chunk(value_code = "#{local_name}")
"\#{URI.escape(#{value_code}, ActionController::Routing::Segment::UNSAFE_PCHAR)}" "\#{URI.escape(#{value_code}.to_s, ActionController::Routing::Segment::UNSAFE_PCHAR)}"
end end
def string_structure(prior_segments) def string_structure(prior_segments)
@ -776,8 +771,8 @@ module ActionController
end end
# Don't URI.escape the controller name since it may contain slashes. # Don't URI.escape the controller name since it may contain slashes.
def interpolation_chunk(value_code = "#{local_name}.to_s") def interpolation_chunk(value_code = "#{local_name}")
"\#{#{value_code}}" "\#{#{value_code}.to_s}"
end end
# Make sure controller names like Admin/Content are correctly normalized to # Make sure controller names like Admin/Content are correctly normalized to
@ -799,8 +794,8 @@ module ActionController
RESERVED_PCHAR = "#{Segment::RESERVED_PCHAR}/" RESERVED_PCHAR = "#{Segment::RESERVED_PCHAR}/"
UNSAFE_PCHAR = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}#{RESERVED_PCHAR}]", false, 'N').freeze UNSAFE_PCHAR = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}#{RESERVED_PCHAR}]", false, 'N').freeze
def interpolation_chunk(value_code = "#{local_name}.to_s") def interpolation_chunk(value_code = "#{local_name}")
"\#{URI.escape(#{value_code}, ActionController::Routing::PathSegment::UNSAFE_PCHAR)}" "\#{URI.escape(#{value_code}.to_s, ActionController::Routing::PathSegment::UNSAFE_PCHAR)}"
end end
def default def default

View File

@ -33,11 +33,11 @@ class ResourcesTest < Test::Unit::TestCase
# The assertions in these tests are incompatible with the hash method # The assertions in these tests are incompatible with the hash method
# optimisation. This could indicate user level problems # optimisation. This could indicate user level problems
def setup def setup
ActionController::Routing.optimise_named_routes = false ActionController::Base.optimise_named_routes = false
end end
def tear_down def tear_down
ActionController::Routing.optimise_named_routes = true ActionController::Base.optimise_named_routes = true
end end
def test_should_arrange_actions def test_should_arrange_actions

View File

@ -48,7 +48,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
attr_reader :rs attr_reader :rs
def setup def setup
# These tests assume optimisation is on, so re-enable it. # These tests assume optimisation is on, so re-enable it.
ActionController::Routing.optimise_named_routes = true ActionController::Base.optimise_named_routes = true
@rs = ::ActionController::Routing::RouteSet.new @rs = ::ActionController::Routing::RouteSet.new
@rs.draw {|m| m.connect ':controller/:action/:id' } @rs.draw {|m| m.connect ':controller/:action/:id' }
@ -852,6 +852,11 @@ class DynamicSegmentTest < Test::Unit::TestCase
assert_equal a_value, eval(%("#{segment.interpolation_chunk}")) assert_equal a_value, eval(%("#{segment.interpolation_chunk}"))
end end
def test_interpolation_chunk_should_accept_nil
a_value = nil
assert_equal '', eval(%("#{segment.interpolation_chunk('a_value')}"))
end
def test_value_regexp_should_be_nil_without_regexp def test_value_regexp_should_be_nil_without_regexp
assert_equal nil, segment.value_regexp assert_equal nil, segment.value_regexp
end end