summary refs log tree commit
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2022-04-04 13:25:33 -0700
committerGitHub <noreply@github.com>2022-04-04 13:25:33 -0700
commitde538def20faf1a90b4f72245f33cf06ec435d05 (patch)
tree7782104d173595b41f5e484997dcaf2c42ece43a
parent9a018c0c8fea537a8f8744000ae1dcb3e93cacb9 (diff)
parentdf23f57407426a85245e35d8c0c7c90d53dcb74a (diff)
downloadrack-de538def20faf1a90b4f72245f33cf06ec435d05.tar.gz
Merge pull request #1837 from RubyElders/custom-range-exception
Use custom exception on params too deep error.
-rw-r--r--lib/rack/query_parser.rb6
-rw-r--r--test/spec_request.rb4
-rw-r--r--test/spec_utils.rb2
3 files changed, 8 insertions, 4 deletions
diff --git a/lib/rack/query_parser.rb b/lib/rack/query_parser.rb
index 9d81dac5..ef065b3f 100644
--- a/lib/rack/query_parser.rb
+++ b/lib/rack/query_parser.rb
@@ -14,6 +14,10 @@ module Rack
     # sequence.
     class InvalidParameterError < ArgumentError; end
 
+    # ParamsTooDeepError is the error that is raised when params are recursively
+    # nested over the specified limit.
+    class ParamsTooDeepError < RangeError; end
+
     def self.make_default(_key_space_limit=(not_deprecated = true; nil), param_depth_limit)
       unless not_deprecated
         warn("`first argument `key_space limit` is deprecated and no longer has an effect. Please call with only one argument, which will be required in a future version of Rack", uplevel: 1)
@@ -91,7 +95,7 @@ module Rack
     end
 
     private def _normalize_params(params, name, v, depth)
-      raise RangeError if depth >= param_depth_limit
+      raise ParamsTooDeepError if depth >= param_depth_limit
 
       if !name
         # nil name, treat same as empty string (required by tests)
diff --git a/test/spec_request.rb b/test/spec_request.rb
index fe1f56aa..3818dc1b 100644
--- a/test/spec_request.rb
+++ b/test/spec_request.rb
@@ -400,7 +400,7 @@ class RackRequestTest < Minitest::Spec
   it "limit the allowed parameter depth when parsing parameters" do
     env = Rack::MockRequest.env_for("/?a#{'[a]' * 40}=b")
     req = make_request(env)
-    lambda { req.GET }.must_raise RangeError
+    lambda { req.GET }.must_raise Rack::QueryParser::ParamsTooDeepError
 
     env = Rack::MockRequest.env_for("/?a#{'[a]' * 30}=b")
     req = make_request(env)
@@ -416,7 +416,7 @@ class RackRequestTest < Minitest::Spec
 
       env = Rack::MockRequest.env_for("/?a[a][a][a]=b")
       req = make_request(env)
-      lambda { make_request(env).GET  }.must_raise RangeError
+      lambda { make_request(env).GET  }.must_raise Rack::QueryParser::ParamsTooDeepError
     ensure
       Rack::Utils.param_depth_limit = old
     end
diff --git a/test/spec_utils.rb b/test/spec_utils.rb
index b368d204..354ea56f 100644
--- a/test/spec_utils.rb
+++ b/test/spec_utils.rb
@@ -144,7 +144,7 @@ describe Rack::Utils do
 
     lambda {
       Rack::Utils.parse_nested_query("foo#{"[a]" * len}=bar")
-    }.must_raise(RangeError)
+    }.must_raise(Rack::QueryParser::ParamsTooDeepError)
 
     Rack::Utils.parse_nested_query("foo#{"[a]" * (len - 1)}=bar")
   end