Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safe strings for urls in rails?

Is there a built in way to convert a string so it is safe in a url?

like image 327
Blankman Avatar asked Apr 07 '11 04:04

Blankman


People also ask

Can I use UUID in URL?

Yes. A UUID consists of only hexadecimal characters (a–f, 0–9) plus a hyphen (-). As per RFC 3986 (URI Syntax) §2.3, hyphen and hexadecimal characters are included in those explicitly unreserved: Characters that are allowed in a URI but do not have a reserved purpose are called unreserved.

How do I encode a URL in Ruby?

If you need to encode query strings then CGI. escape method is probably what you're looking for. CGI. escape follows the CGI/HTML forms spec and returns a string like application/x-www-form-urlencoded requests, which requires spaces to be escaped to + and encode most special characters.

What does CGI escape do?

CGI. escape is for escaping a URL value in the query string. All characters that don't fall into the ALPHA, DIGIT, '_', '-', '.


1 Answers

CGI::escape()

To decode: CGI::unescape()

like image 56
Raisen Avatar answered Sep 20 '22 06:09

Raisen