URL escaping in Ruby con CGI::escape


E’ da un po’ che non scrivo ed ecco un piccolo aggiornamento.

Parliamo di URLs e dei caratteri ammessi in questo tipo di oggetti. Il documento RFC 1738 del ‘94 prevede solo alcuni caratteri per l’identificazione di URLs:

only alphanumerics, the special characters “$-_.+!*’(),”, and reserved characters used for their reserved purposes may be used unencoded within a URL.

Per eseguire questa operazione di escaping Ruby offre una semplice funzione di libreria:

CGI::escape

Esempio:

url_encoded_string = CGI::escape("'Stop!' said Fred")
     # => "%27Stop%21%27+said+Fred"

Per maggiori informazioni:
http://ruby-doc.org/core/classes/CGI.html#M000532

Articoli correlati

This entry was posted in Ruby and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">