Skip to content

Commit dc1bd14

Browse files
Escape single quotes surrounded by double quotes (#63229) (#63438)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 3568986 commit dc1bd14

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/plugins/console/public/application/models/sense_editor/__tests__/editor_input1.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ GET index_1/type1/1/_source?_source_include=f
2525

2626
DELETE index_2
2727

28+
29+
POST /_sql?format=txt
30+
{
31+
"query": "SELECT prenom FROM claude_index WHERE prenom = 'claude' ",
32+
"fetch_size": 1
33+
}

src/plugins/console/public/application/models/sense_editor/__tests__/sense_editor.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,18 @@ curl -XGET "http://localhost:9200/_stats?level=shards"
470470
curl -XPUT "http://localhost:9200/index_1/type1/1" -H 'Content-Type: application/json' -d'
471471
{
472472
"f": 1
473+
}'`.trim()
474+
);
475+
476+
multiReqCopyAsCurlTest(
477+
'with single quotes',
478+
editorInput1,
479+
{ start: { lineNumber: 29 }, end: { lineNumber: 33 } },
480+
`
481+
curl -XPOST "http://localhost:9200/_sql?format=txt" -H 'Content-Type: application/json' -d'
482+
{
483+
"query": "SELECT prenom FROM claude_index WHERE prenom = '\\''claude'\\'' ",
484+
"fetch_size": 1
473485
}'`.trim()
474486
);
475487
});

src/plugins/console/public/application/models/sense_editor/sense_editor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,9 @@ export class SenseEditor {
484484
if (esData && esData.length) {
485485
ret += " -H 'Content-Type: application/json' -d'\n";
486486
const dataAsString = collapseLiteralStrings(esData.join('\n'));
487-
// since Sense doesn't allow single quote json string any single qoute is within a string.
488-
ret += dataAsString.replace(/'/g, '\\"');
487+
488+
// We escape single quoted strings that that are wrapped in single quoted strings
489+
ret += dataAsString.replace(/'/g, "'\\''");
489490
if (esData.length > 1) {
490491
ret += '\n';
491492
} // end with a new line

0 commit comments

Comments
 (0)