Method: HTTPTools::Encoding.url_decode
- Defined in:
- lib/http_tools/encoding.rb
.url_decode(string) ⇒ Object
:call-seq: Encoding.url_decode(encoded_string) -> string
URL decode a string, eg “le+caf%c3%a9” becomes “le café”
38 39 40 41 42 43 |
# File 'lib/http_tools/encoding.rb', line 38 def url_decode(string) string.tr(PLUS, SPACE).gsub(/(%[0-9a-fA-F]{2})+/) do |match| r = [match.delete(PERCENT)].pack(HEX_BIG_ENDIAN_REPEATING) r.respond_to?(:force_encoding) ? r.force_encoding(string.encoding) : r end end |