Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape single quotes into double quotes into single quotes

Tags:

json

curl

Here is an example of command line that fit this description :

curl  http://dumbdomain.com/solr/collection2/update/json -H 'Content-type:application/json' -d ' { "add": { "doc": { "uid": "79729", "text" : "I''ve got your number"} } }' 

I already tried \' (not escaped), url encoded (not urldecoded at this other end!) and '' (quote disappear!), without success.

like image 354
Pr Shadoko Avatar asked Sep 04 '13 11:09

Pr Shadoko


People also ask

How do you escape a single quote in a double quote?

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

How do you escape quotes within a quote?

It's done by finishing an already-opened one ( ' ), placing the escaped one ( \' ), and then opening another one ( ' ). It's done by finishing already opened one ( ' ), placing a quote in another quote ( "'" ), and then opening another one ( ' ).

Can you use single quotes instead of double quotes?

In US English, you must use double quotation marks. Single quotation marks are used for quotes within quotes. In UK English, it's most common to use single quotation marks, with double quotation marks for quotes within quotes, although the other way around is acceptable too.

What is the rule for using single quotation marks?

Single quotation marks are used to indicate quotations inside of other quotations. “Jessie said, 'Goodbye,'” Ben said. This is Ben talking, so his words go in quotation marks. But because we're quoting Ben quoting someone else, Jessie, we use single quotation marks to indicate the quote within the quote.


1 Answers

If you replace ' by unicode encoded ' (which is \u0027), then it works:

curl http://dumbdomain.com/solr/collection2/update/json -H 'Content-type:application/json' -d ' { "add": { "doc": { "uid": "79729", "text" : "I\u0027ve got your number"} } }' 

Strange, but worth to know!

like image 176
Pr Shadoko Avatar answered Oct 23 '22 15:10

Pr Shadoko