-2

I would like to accept simple quotes into a string without crashing my curl request.

here my curl request :

curl -XGET "localhost:9200/test/all/_search?pretty" -d \'{"query":"'+question+'"}\'';

If question = 'It's OK'.

I will have an error durong my request

 Syntax error: Unterminated quoted string

For the moment I tried several solutions (like this one below), but none worked :

question = question.replace(/'/g, "\\'");

Have you got a solution to fix it ?

onedkr
  • 3,226
  • 3
  • 21
  • 31

1 Answers1

0

The following works OK, guess you just need to escape your backslashes

let question = "lskdlskd'sldklskd"; question = question.replace(/'/g, "\\\\'");

Keir
  • 483
  • 3
  • 10
  • It doesn't work, I have still the unterminated quoted string error. `'It's ok'` become ----> `'it\\'s ok'` – onedkr Nov 21 '16 at 14:50