lmenezes / cerebro

MIT License
5.49k stars 712 forks source link

Should escape single quotes when a request is copied as a curl script #324

Open hokkun-dayo opened 5 years ago

hokkun-dayo commented 5 years ago

Sometimes we includes single quotes in our request body of REST request (at the /#/rest page). For curl scripts, we need to escape single quotes by '\'' because the part of current codes uses single quotes for the -d option of curl command.

Example

POST _reindex
{
  "source": {
    "index": "metricbeat-*"
  },
  "dest": {
    "index": "metricbeat"
  },
  "script": {
    "lang": "painless",
    "source": "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'"
  }
}

(from https://www.elastic.co/guide/en/elasticsearch/reference/5.6/docs-reindex.html)

In this case, 'metricbeat-' should be '\''metricbeat-'\''.

I've already worked on this change for my forked repository, so if you agree with me I'll submit a new PR to the base repository here.

hokkun-dayo commented 5 years ago

wip PR: https://github.com/hokkun-dayo/cerebro/pull/1