I'm trying to use URI.encode to properly escape a query parameter to an HTTP GET request. The string that I am encoding contains a non-ascii (UTF-8) accented character.
s = "é" # lowercase e with acute accent
s.encoding # => #<Encoding:UTF-8>
s.length # => 1
s.chars.to_a # => "é"
but then
require 'uri'
URI.encode(s) # => "%C3%A9"
URI.escape(s) # => "%C3%A9"
URI.encode_www_form_component(s) # => "%C3%A9"
URI.encode_www_form(:foo => s) # => "foo=%C3%A9"
Why is it doing this, when the proper encoding should be "%E9" ? How do I use Ruby to encode the string correctly?