File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
src/legacy/core_plugins/console/public/np_ready/lib/utils Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -52,3 +52,33 @@ Correctly handle new lines in triple quotes
5252 SELECT * FROM "TABLE"
5353 """
5454}
55+ ==========
56+ Single quotes escaped special case, start and end
57+ -------------------------------------
58+ {
59+ "query": "\"test\""
60+ }
61+ -------------------------------------
62+ {
63+ "query": "\"test\""
64+ }
65+ ==========
66+ Single quotes escaped special case, start
67+ -------------------------------------
68+ {
69+ "query": "\"test"
70+ }
71+ -------------------------------------
72+ {
73+ "query": "\"test"
74+ }
75+ ==========
76+ Single quotes escaped special case, end
77+ -------------------------------------
78+ {
79+ "query": "test\""
80+ }
81+ -------------------------------------
82+ {
83+ "query": "test\""
84+ }
Original file line number Diff line number Diff line change @@ -84,6 +84,20 @@ export function expandLiteralStrings(data: string) {
8484 // Expand to triple quotes if there are _any_ slashes
8585 if ( string . match ( / \\ ./ ) ) {
8686 const firstDoubleQuoteIdx = string . indexOf ( '"' ) ;
87+ const lastDoubleQuoteIdx = string . lastIndexOf ( '"' ) ;
88+
89+ // Handle a special case where we may have a value like "\"test\"". We don't
90+ // want to expand this to """"test"""" - so we terminate before processing the string
91+ // further if we detect this either at the start or end of the double quote section.
92+
93+ if ( string [ firstDoubleQuoteIdx + 1 ] === '\\' && string [ firstDoubleQuoteIdx + 2 ] === '"' ) {
94+ return string ;
95+ }
96+
97+ if ( string [ lastDoubleQuoteIdx - 1 ] === '"' && string [ lastDoubleQuoteIdx - 2 ] === '\\' ) {
98+ return string ;
99+ }
100+
87101 const colonAndAnySpacing = string . slice ( 0 , firstDoubleQuoteIdx ) ;
88102 const rawStringifiedValue = string . slice ( firstDoubleQuoteIdx , string . length ) ;
89103 // Remove one level of JSON stringification
You can’t perform that action at this time.
0 commit comments