class Escape::PercentEncoded
Public Instance Methods
split_html_form()
click to toggle source
#split_html_form decodes percent-encoded string as application/x-www-form-urlencoded defined by HTML specification.
It recognizes “&” and “;” as a separator of key-value pairs.
If it find is not valid as application/x-www-form-urlencoded, Escape::InvalidHTMLForm exception is raised.
Escape::PercentEncoded.new("a=b&c=d") #=> [[#<Escape::PercentEncoded: a>, #<Escape::PercentEncoded: b>], [#<Escape::PercentEncoded: c>, #<Escape::PercentEncoded: d>]] Escape::PercentEncoded.new("a=b;c=d").split_html_form #=> [[#<Escape::PercentEncoded: a>, #<Escape::PercentEncoded: b>], [#<Escape::PercentEncoded: c>, #<Escape::PercentEncoded: d>]] Escape::PercentEncoded.new("%3D=%3F").split_html_form #=> [[#<Escape::PercentEncoded: %3D>, #<Escape::PercentEncoded: %3F>]]
# File escape.rb, line 152 def split_html_form assoc = [] @str.split(/[&;]/, -1).each {|s| raise InvalidHTMLForm, "invalid: #{@str}" unless /=/ =~ s k = $` v = $' k.gsub!(/\+/, ' ') v.gsub!(/\+/, ' ') assoc << [PercentEncoded.new_no_dup(k), PercentEncoded.new_no_dup(v)] } assoc end