File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
frontend/src/components/advancedSearch/utils Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,19 @@ declare var status: "Available" | "Running";`;
9898 expect ( generateGlobalVarDeclarations ( objects ) ) . toBe ( expected ) ;
9999 } ) ;
100100
101+ it ( 'should escape double quotes and backslashes in string literals' , ( ) => {
102+ const objects = [
103+ { value : '"quote"' } ,
104+ { value : 'backslash\\' } ,
105+ { value : 'both\\"' } ,
106+ { value : 'plain' } ,
107+ ] ;
108+ const expected =
109+ 'declare var value: "\\"quote\\"" | "backslash\\\\" | "both\\\\\\"" | "plain";' ;
110+
111+ expect ( generateGlobalVarDeclarations ( objects ) ) . toBe ( expected ) ;
112+ } ) ;
113+
101114 it ( 'should handle keys that are not valid identifiers by skipping them' , ( ) => {
102115 const objects = [ { 'not-valid' : 1 , validKey : 2 } ] ;
103116 const expected = 'declare var validKey: number;' ;
Original file line number Diff line number Diff line change @@ -138,7 +138,7 @@ function generateTypeString(
138138 // Add quoted literals
139139 node . stringLiterals . forEach ( literal => {
140140 // Basic escaping for quotes inside the string literal itself
141- const escapedLiteral = literal . replace ( / " / g, '\\"' ) ;
141+ const escapedLiteral = literal . replace ( / \\ / g , '\\\\' ) . replace ( / " / g, '\\"' ) ;
142142 types . push ( `"${ escapedLiteral } "` ) ;
143143 } ) ;
144144 } else {
You can’t perform that action at this time.
0 commit comments