lib/rack/query_parser.rb in rack-2.1.4.4 vs lib/rack/query_parser.rb in rack-2.2.0
- old
+ new
@@ -1,12 +1,10 @@
# frozen_string_literal: true
-require_relative 'core_ext/regexp'
-
module Rack
class QueryParser
- using ::Rack::RegexpExtensions
+ (require_relative 'core_ext/regexp'; using ::Rack::RegexpExtensions) if RUBY_VERSION < '2.4'
DEFAULT_SEP = /[&;] */n
COMMON_SEP = { ";" => /[;] */n, ";," => /[;,] */n, "&" => /[&] */n }
# ParameterTypeError is the error that is raised when incoming structural
@@ -62,21 +60,22 @@
# types are Arrays, Hashes and basic value types. It is possible to supply
# query strings with parameters of conflicting types, in this case a
# ParameterTypeError is raised. Users are encouraged to return a 400 in this
# case.
def parse_nested_query(qs, d = nil)
- return {} if qs.nil? || qs.empty?
params = make_params
- qs.split(d ? (COMMON_SEP[d] || /[#{d}] */n) : DEFAULT_SEP).each do |p|
- k, v = p.split('=', 2).map! { |s| unescape(s) }
+ unless qs.nil? || qs.empty?
+ (qs || '').split(d ? (COMMON_SEP[d] || /[#{d}] */n) : DEFAULT_SEP).each do |p|
+ k, v = p.split('=', 2).map! { |s| unescape(s) }
- normalize_params(params, k, v, param_depth_limit)
+ normalize_params(params, k, v, param_depth_limit)
+ end
end
return params.to_h
rescue ArgumentError => e
- raise InvalidParameterError, e.message
+ raise InvalidParameterError, e.message, e.backtrace
end
# normalize_params recursively expands parameters into structural types. If
# the structural types represented by two different parameter names are in
# conflict, a ParameterTypeError is raised.