Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8822155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:02:05+00:00 2026-06-14T06:02:05+00:00

I read the documentation of url_encode . Is there a table that tells me

  • 0

I read the documentation of url_encode.

Is there a table that tells me exactly which character is encoded to what, using url_encode?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:02:07+00:00Added an answer on June 14, 2026 at 6:02 am

    ERB’s url_encode can be tweaked:

    def url_encode(s)
      s.to_s.dup.force_encoding("ASCII-8BIT").gsub(%r[^a-zA-Z0-9_\-.]/) {
        sprintf("%%%02X", $&.unpack("C")[0])
      }
    end
    

    to:

    def url_encode(s, regex=%r[^a-zA-Z0-9_\-.]/)
      s.to_s.dup.force_encoding("ASCII-8BIT").gsub(regex) {
        sprintf("%%%02X", $&.unpack("C")[0])
      }
    end
    
    url_encode('pop', /./)
    => "%70%6F%70"
    

    In addition, Ruby’s CGI and URI modules have the ability to encode URLs, converting restricted characters to entities, so don’t overlook their offerings.

    For instance, escaping characters for URL parameters:

    CGI.escape('http://www.example.com')
    => "http%3A%2F%2Fwww.example.com"
    
    CGI.escape('<body><p>foo</p></body>')
    => "%3Cbody%3E%3Cp%3Efoo%3C%2Fp%3E%3C%2Fbody%3E"
    

    Ruby CGI’s escape also uses a small regex to figure out which characters should be escaped in a URL. This is the method’s definition from the documentation:

    def CGI::escape(string)
      string.gsub(%r([^ a-zA-Z0-9_.-]+)/) do
        '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
      end.tr(' ', '+')
    end
    

    You also override that and change the regex, or expose it for your own use inside your redefinition of the method:

    def CGI::escape(string, escape_regex=%r([^ a-zA-Z0-9_.-]+)/)
      string.gsub(escape_regex) do
        '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
      end.tr(' ', '+')
    end
    

    URI.encode_www_form_component also does a similar encoding, the only differences in characters are * and :

    URI.encode_www_form_component('<p>foo</p>')
    => "%3Cp%3Efoo%3C%2Fp%3E"
    

    And, similarly to overriding CGI::escape, you can override the regex in URI.encode_www_form_component:

    def self.encode_www_form_component(str, regex=%r[^*\-.0-9A-Z_a-z]/)
      str = str.to_s
      if HTML5ASCIIINCOMPAT.include?(str.encoding)
        str = str.encode(Encoding::UTF_8)
      else
        str = str.dup
      end
      str.force_encoding(Encoding::ASCII_8BIT)
      str.gsub!(regex, TBLENCWWWCOMP_)
      str.force_encoding(Encoding::US_ASCII)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read documentation for functions such as values and define-values that return and
I've read the documentation here . I have an action, cook, which is applied
I have read the documentation that states that "given the type of the enum,
So, I've read the IPN documentation and I've read tons of examples that I've
I'm using google maps with PHP/MSQL, i've read the documentation on google and take
I'm trying to read in an image URL. As mentioned in the java documentation,
I am new to OSX user space development. I've read documentation and googled before
Having read the documentation for VPython and GTK threading , it seems to me
Having read the documentation of Java's String class, it doesn't appear to support popping
I read the documentation, but I did not understand what is the purpose of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.