Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

CGI::Util#escapeURIComponent

escapeURIComponent(string)

URL-encode a string following RFC 3986 Space characters (+“ ”+) are encoded with (+“%20”+)

Example
url_encoded_string = CGI.escapeURIComponent("'Stop!' said Fred")
   # => "%27Stop%21%27%20said%20Fred"