Skip to content

Commit 7536cc2

Browse files
Handle another double quote special case (#54474) (#54561)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent e3c2f31 commit 7536cc2

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/legacy/core_plugins/console/public/quarantined/src/utils.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ utils.expandLiteralStrings = function(data) {
8888
// Expand to triple quotes if there are _any_ slashes
8989
if (string.match(/\\./)) {
9090
const firstDoubleQuoteIdx = string.indexOf('"');
91+
const lastDoubleQuoteIdx = string.lastIndexOf('"');
92+
93+
// Handle a special case where we may have a value like "\"test\"". We don't
94+
// want to expand this to """"test"""" - so we terminate before processing the string
95+
// further if we detect this either at the start or end of the double quote section.
96+
97+
if (string[firstDoubleQuoteIdx + 1] === '\\' && string[firstDoubleQuoteIdx + 2] === '"') {
98+
return string;
99+
}
100+
101+
if (string[lastDoubleQuoteIdx - 1] === '"' && string[lastDoubleQuoteIdx - 2] === '\\') {
102+
return string;
103+
}
104+
91105
const colonAndAnySpacing = string.slice(0, firstDoubleQuoteIdx);
92106
const rawStringifiedValue = string.slice(firstDoubleQuoteIdx, string.length);
93107
const jsonValue = JSON.parse(rawStringifiedValue)

src/legacy/core_plugins/console/public/quarantined/tests/src/utils_string_expanding.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,33 @@ Correctly parse with JSON embedded inside values
4040
"content\\\\": """ { "json": "inside\\" ok! 1
4141
" } """
4242
}
43+
==========
44+
Single quotes escaped special case, start and end
45+
-------------------------------------
46+
{
47+
"query": "\"test\""
48+
}
49+
-------------------------------------
50+
{
51+
"query": "\"test\""
52+
}
53+
==========
54+
Single quotes escaped special case, start
55+
-------------------------------------
56+
{
57+
"query": "\"test"
58+
}
59+
-------------------------------------
60+
{
61+
"query": "\"test"
62+
}
63+
==========
64+
Single quotes escaped special case, end
65+
-------------------------------------
66+
{
67+
"query": "test\""
68+
}
69+
-------------------------------------
70+
{
71+
"query": "test\""
72+
}

0 commit comments

Comments
 (0)