From 30215c37d1da0cf611854fcc246fe115d166008b Mon Sep 17 00:00:00 2001 From: Gibheer Date: Tue, 6 Aug 2013 14:15:54 +0200 Subject: make it possible to push lists as paramters This makes it possible to push lists as paramters by naming the variables with `[]` at the end, for example `foo[]`. --- lib/zero/request/parameter.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/zero/request/parameter.rb b/lib/zero/request/parameter.rb index ac67401..c8d324c 100644 --- a/lib/zero/request/parameter.rb +++ b/lib/zero/request/parameter.rb @@ -21,6 +21,8 @@ module Zero 'application/x-www-form-urlencoded', 'multipart/form-data' ].to_set + # match keys for list attribute + REGEX_MATCH_LIST = /\[\]$/ # get the query parameters attr_reader :query @@ -95,7 +97,16 @@ module Zero # @param query [String] the query string # @return [Hash] the key/valuie pairs def parse_string(query) - Hash[URI.decode_www_form(query)] + result = {} + URI.decode_www_form(query).each do |p| + if p.first.match(REGEX_MATCH_LIST) + result[p.first] ||= [] + result[p.first] << p.last + else + result[p.first] = p.last + end + end + result end end end -- cgit v1.2.3-70-g09d2