From de0a0d700e8c3959a3503152b9a495616afbeae5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 21 Feb 2007 10:05:07 +0000 Subject: Routing: better support for escaped values in route segments. Closes #7544. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6185 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/routing.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_controller/routing.rb') diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 58207eed74..723aaada83 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -412,7 +412,7 @@ module ActionController def recognition_extraction next_capture = 1 extraction = segments.collect do |segment| - x = segment.match_extraction next_capture + x = segment.match_extraction(next_capture) next_capture += Regexp.new(segment.regexp_chunk).number_of_captures x end @@ -694,7 +694,7 @@ module ActionController end def interpolation_chunk - "\#{URI.escape(#{local_name}.to_s)}" + "\#{CGI.escape(#{local_name}.to_s)}" end def string_structure(prior_segments) @@ -725,10 +725,17 @@ module ActionController optional? ? Regexp.optionalize(pattern) : pattern end def match_extraction(next_capture) - hangon = (default ? "|| #{default.inspect}" : "if match[#{next_capture}]") - # All non code-related keys (such as :id, :slug) have to be unescaped as other CGI params - "params[:#{key}] = match[#{next_capture}] #{hangon}" + default_value = default ? default.inspect : nil + %[ + value = if (m = match[#{next_capture}]) + m = m.gsub('+', '%2B') + CGI.unescape(m) + else + #{default_value} + end + params[:#{key}] = value if value + ] end def optionality_implied? @@ -1292,7 +1299,6 @@ module ActionController end def recognize_path(path, environment={}) - path = URI.unescape(path) routes.each do |route| result = route.recognize(path, environment) and return result end -- cgit v1.2.3