class Rack::QueryParser
def _normalize_params(params, name, v, depth)
def _normalize_params(params, name, v, depth) ParamsTooDeepError if depth >= param_depth_limit me l name, treat same as empty string (required by tests) after = '' depth == 0 art of parsing, don't treat [] or [ at start of string specially tart = name.index('[', 1) Start of parameter nesting, use part before brackets as key = name[0, start] ter = name[start, name.length] Plain parameter with no nesting = name ter = '' name.start_with?('[]') ray nesting '[]' r = name[2, name.length] name.start_with?('[') && (start = name.index(']', 1)) sh nesting, use the part inside brackets as the key name[1, start-1] r = name[start+1, name.length] obably malformed input, nested but not starting with [ eat full name as key for backwards compatibility. name r = '' if k.empty? er == '' == '[]' && depth != 0 turn [v] rams[k] = v after == "[" ms[name] = v after == "[]" ms[k] ||= [] e ParameterTypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array) ms[k] << v after.start_with?('[]') cognize x[][y] (hash inside array) parameters ss after[2] == '[' && after.end_with?(']') && (child_key = after[3, after.length-4]) && !child_key.empty? && !child_key.index('[') && !child_key.index(']') Handle other nested array parameters ild_key = after[2, after.length] ms[k] ||= [] e ParameterTypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array) arams_hash_type?(params[k].last) && !params_hash_has_key?(params[k].last, child_key) ormalize_params(params[k].last, child_key, v, depth + 1) rams[k] << _normalize_params(make_params, child_key, v, depth + 1) ms[k] ||= make_params e ParameterTypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params_hash_type?(params[k]) ms[k] = _normalize_params(params[k], after, v, depth + 1)