v1_9_2_180 - Show latest stable - 0 notes - Class: URI
decode_www_form(str, enc=Encoding::UTF_8) public

Decode URL-encoded form data from given str.

This decodes application/x-www-form-urlencoded data and returns array of key-value array. This internally uses URI.decode_www_form_component.

charset hack is not supported now because the mapping from given charset to Ruby’s encoding is not clear yet. see also http://www.w3.org/TR/html5/syntax.html#character-encodings-0

This refers http://www.w3.org/TR/html5/forms.html#url-encoded-form-data

ary = URI.decode_www_form(“a=1&a=2&b=3”) p ary #=> [[‘a’, ‘1’], [‘a’, ‘2’], [‘b’, ‘3’]] p ary.assoc(‘a’).last #=> ‘1’ p ary.assoc(‘b’).last #=> ‘3’ p ary.rassoc(‘a’).last #=> ‘2’ p Hash[ary] # => {“a”=>“2”, “b”=>“3”}

See URI.decode_www_form_component, URI.encode_www_form

Show source
Register or log in to add new notes.