Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't URI.escape escape single quotes?

Tags:

url

uri

ruby

Why doesn't URI.escape escape single quotes?

URI.escape("foo'bar\" baz")
=> "foo'bar%22%20baz"
like image 805
John Bachir Avatar asked Oct 11 '11 20:10

John Bachir


People also ask

What is the escape character for single quote?

No escaping is used with single quotes. Use a double backslash as the escape character for backslash.

How do you escape a single quote in JavaScript?

We can use the backslash ( \ ) escape character to prevent JavaScript from interpreting a quote as the end of the string. The syntax of \' will always be a single quote, and the syntax of \" will always be a double quote, without any fear of breaking the string.

How do I pass a single quote in query string?

The simplest method to escape single quotes in SQL is to use two single quotes. For example, if you wanted to show the value O'Reilly, you would use two quotes in the middle instead of one. The single quote is the escape character in Oracle, SQL Server, MySQL, and PostgreSQL.

What is the use of &apos?

' means "HTML Code for an Apostrophe."


1 Answers

For the same reason it doesn't escape ? or / or :, and so forth. URI.escape() only escapes characters that cannot be used in URLs at all, not characters that have a special meaning.

What you're looking for is CGI.escape():

require "cgi"
CGI.escape("foo'bar\" baz")
=> "foo%27bar%22+baz"
like image 159
molf Avatar answered Oct 21 '22 04:10

molf