Skip to content

Commit

Permalink
Escape single quotes surrounded by double quotes (elastic#63229) (ela…
Browse files Browse the repository at this point in the history
…stic#63438)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
jloleysens and elasticmachine authored Apr 14, 2020
1 parent 3568986 commit dc1bd14
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ GET index_1/type1/1/_source?_source_include=f

DELETE index_2


POST /_sql?format=txt
{
"query": "SELECT prenom FROM claude_index WHERE prenom = 'claude' ",
"fetch_size": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,18 @@ curl -XGET "http://localhost:9200/_stats?level=shards"
curl -XPUT "http://localhost:9200/index_1/type1/1" -H 'Content-Type: application/json' -d'
{
"f": 1
}'`.trim()
);

multiReqCopyAsCurlTest(
'with single quotes',
editorInput1,
{ start: { lineNumber: 29 }, end: { lineNumber: 33 } },
`
curl -XPOST "http://localhost:9200/_sql?format=txt" -H 'Content-Type: application/json' -d'
{
"query": "SELECT prenom FROM claude_index WHERE prenom = '\\''claude'\\'' ",
"fetch_size": 1
}'`.trim()
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,9 @@ export class SenseEditor {
if (esData && esData.length) {
ret += " -H 'Content-Type: application/json' -d'\n";
const dataAsString = collapseLiteralStrings(esData.join('\n'));
// since Sense doesn't allow single quote json string any single qoute is within a string.
ret += dataAsString.replace(/'/g, '\\"');

// We escape single quoted strings that that are wrapped in single quoted strings
ret += dataAsString.replace(/'/g, "'\\''");
if (esData.length > 1) {
ret += '\n';
} // end with a new line
Expand Down

0 comments on commit dc1bd14

Please sign in to comment.