January 2024
Intermediate to advanced
718 pages
20h 15m
English
The Ruby standard distribution includes some core utilities as part of the CGI class and CGI::Util module.
When dealing with URLs and HTML code, you must be careful to quote certain characters. For instance, a slash character ( / ) has special meaning in a URL, so it must be “escaped” if it’s not part of the path name. That is, any / in the query portion of the URL is translated to the string %2F, and then it must be translated back to a / for you to use it. Space and ampersand are also special characters.
To handle this, CGI provides the methods escape and unescape:
| | require "cgi" |
| | puts CGI.escape("Nicholas Payton/Trumpet & Flugel Horn") |
Produces:
| | Nicholas+Payton%2FTrumpet+%26+Flugel+Horn |
More frequently, ...
Read now
Unlock full access