move path_parameter encoding check to the request object

This commit is contained in:
Aaron Patterson 2014-05-27 14:01:30 -07:00
parent 97a52283f8
commit 4797c4caca
3 changed files with 13 additions and 18 deletions

@ -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?)
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.