Permalink
Browse files

move path_parameter encoding check to the request object

  • Loading branch information...
1 parent 97a5228 commit 4797c4caca52b415bc2233254e2503a8e3752c15 @tenderlove tenderlove committed May 27, 2014
@@ -53,6 +53,17 @@ def initialize(env)
@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?)
majkelcc
majkelcc Oct 6, 2014

❤️ fixes issues with nil's

+ unless value.valid_encoding?
+ raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}"
+ end
+ end
+ end
+
def key?(key)
@env.key?(key)
end
@@ -22,14 +22,7 @@ def call(env)
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
@@ -30,18 +30,9 @@ def initialize(defaults)
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.

0 comments on commit 4797c4c

Please sign in to comment.