Skip to content

Commit

Permalink
Handle another double quote special case
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Jan 10, 2020
1 parent cc09f61 commit 6022622
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
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

0 comments on commit 6022622

Please sign in to comment.