File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
src/platform/packages/shared/kbn-esql-ast/src/parser Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,42 @@ describe('literal expression', () => {
116116 ] ,
117117 } ) ;
118118 } ) ;
119+
120+ it ( 'escape double-quote before backslash' , ( ) => {
121+ const text = `ROW "a\\"\\\\b", 1` ;
122+ const { root } = parse ( text ) ;
123+
124+ expect ( root . commands [ 0 ] ) . toMatchObject ( {
125+ type : 'command' ,
126+ args : [
127+ {
128+ type : 'literal' ,
129+ literalType : 'keyword' ,
130+ name : '"a\\"\\\\b"' ,
131+ valueUnquoted : 'a"\\b' ,
132+ } ,
133+ { } ,
134+ ] ,
135+ } ) ;
136+ } ) ;
137+
138+ it ( 'escape backslash before double-quote' , ( ) => {
139+ const text = `ROW "a\\\\\\"b", 1` ;
140+ const { root } = parse ( text ) ;
141+
142+ expect ( root . commands [ 0 ] ) . toMatchObject ( {
143+ type : 'command' ,
144+ args : [
145+ {
146+ type : 'literal' ,
147+ literalType : 'keyword' ,
148+ name : '"a\\\\\\"b"' ,
149+ valueUnquoted : 'a\\"b' ,
150+ } ,
151+ { } ,
152+ ] ,
153+ } ) ;
154+ } ) ;
119155 } ) ;
120156
121157 describe ( 'triple quoted' , ( ) => {
Original file line number Diff line number Diff line change @@ -127,11 +127,11 @@ export function createLiteralString(ctx: StringContext): ESQLLiteral {
127127
128128 if ( ! isTripleQuoted ) {
129129 valueUnquoted = valueUnquoted
130- . replace ( / \\ \\ / g, '\\' )
131130 . replace ( / \\ " / g, '"' )
132131 . replace ( / \\ r / g, '\r' )
133132 . replace ( / \\ n / g, '\n' )
134- . replace ( / \\ t / g, '\t' ) ;
133+ . replace ( / \\ t / g, '\t' )
134+ . replace ( / \\ \\ / g, '\\' ) ;
135135 }
136136
137137 return Builder . expression . literal . string (
You can’t perform that action at this time.
0 commit comments