Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] Handle double quote special case #54474

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,33 @@ Correctly handle new lines in triple quotes
SELECT * FROM "TABLE"
"""
}
==========
Single quotes escaped special case, start and end
-------------------------------------
{
"query": "\"test\""
}
-------------------------------------
{
"query": "\"test\""
}
==========
Single quotes escaped special case, start
-------------------------------------
{
"query": "\"test"
}
-------------------------------------
{
"query": "\"test"
}
==========
Single quotes escaped special case, end
-------------------------------------
{
"query": "test\""
}
-------------------------------------
{
"query": "test\""
}
14 changes: 14 additions & 0 deletions src/legacy/core_plugins/console/public/np_ready/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ export function expandLiteralStrings(data: string) {
// Expand to triple quotes if there are _any_ slashes
if (string.match(/\\./)) {
const firstDoubleQuoteIdx = string.indexOf('"');
const lastDoubleQuoteIdx = string.lastIndexOf('"');

// Handle a special case where we may have a value like "\"test\"". We don't
// want to expand this to """"test"""" - so we terminate before processing the string
// further if we detect this either at the start or end of the double quote section.

if (string[firstDoubleQuoteIdx + 1] === '\\' && string[firstDoubleQuoteIdx + 2] === '"') {
return string;
}

if (string[lastDoubleQuoteIdx - 1] === '"' && string[lastDoubleQuoteIdx - 2] === '\\') {
return string;
}

const colonAndAnySpacing = string.slice(0, firstDoubleQuoteIdx);
const rawStringifiedValue = string.slice(firstDoubleQuoteIdx, string.length);
// Remove one level of JSON stringification
Expand Down