aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-05-27 14:01:30 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-05-27 14:01:30 -0700
commit4797c4caca52b415bc2233254e2503a8e3752c15 (patch)
treeb9e0cde887005839bc54ef0a76897e56d7250666 /actionpack
parent97a52283f89ae45f967f665e8fc8fd991abb967f (diff)
downloadrails-4797c4caca52b415bc2233254e2503a8e3752c15.tar.gz
rails-4797c4caca52b415bc2233254e2503a8e3752c15.tar.bz2
rails-4797c4caca52b415bc2233254e2503a8e3752c15.zip
move path_parameter encoding check to the request object
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/http/request.rb11
-rw-r--r--actionpack/lib/action_dispatch/routing/redirection.rb9
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb11
3 files changed, 13 insertions, 18 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index cdb3e44b3a..dfe258e463 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -53,6 +53,17 @@ module ActionDispatch
@uuid = nil
end
+ def check_path_parameters!
+ # If any of the path parameters has an invalid encoding then
+ # raise since it's likely to trigger errors further on.
+ path_parameters.each do |key, value|
+ next unless value.respond_to?(:valid_encoding?)
+ unless value.valid_encoding?
+ raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}"
+ end
+ end
+ end
+
def key?(key)
@env.key?(key)
end
diff --git a/actionpack/lib/action_dispatch/routing/redirection.rb b/actionpack/lib/action_dispatch/routing/redirection.rb
index c9639bca84..b1b39a5496 100644
--- a/actionpack/lib/action_dispatch/routing/redirection.rb
+++ b/actionpack/lib/action_dispatch/routing/redirection.rb
@@ -22,14 +22,7 @@ module ActionDispatch
end
def serve(req)
- # If any of the path parameters has an invalid encoding then
- # raise since it's likely to trigger errors further on.
- req.path_parameters.each do |key, value|
- unless value.valid_encoding?
- raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}"
- end
- end
-
+ req.check_path_parameters!
uri = URI.parse(path(req.path_parameters, req))
unless uri.host
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 64a9d1cecd..8777a9cd71 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -30,18 +30,9 @@ module ActionDispatch
def dispatcher?; true; end
def serve(req)
+ req.check_path_parameters!
params = req.path_parameters
- # If any of the path parameters has an invalid encoding then
- # raise since it's likely to trigger errors further on.
- params.each do |key, value|
- next unless value.respond_to?(:valid_encoding?)
-
- unless value.valid_encoding?
- raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}"
- end
- end
-
prepare_params!(params)
# Just raise undefined constant errors if a controller was specified as default.