File tree Expand file tree Collapse file tree
packages/web/src/features/search Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,6 +72,32 @@ describe('parseQuerySyntaxIntoIR', () => {
7272 } ) ;
7373 } ) ;
7474
75+ it ( 'unescapes a backslash-escaped newline' , async ( ) => {
76+ const ir = await parseQuerySyntaxIntoIR ( {
77+ query : '"line1\\\nline2"' ,
78+ options : { } ,
79+ prisma,
80+ } ) ;
81+
82+ expect ( ir ) . toMatchObject ( {
83+ query : 'substring' ,
84+ substring : { pattern : 'line1\nline2' } ,
85+ } ) ;
86+ } ) ;
87+
88+ it ( 'preserves backslashes before other characters' , async ( ) => {
89+ const ir = await parseQuerySyntaxIntoIR ( {
90+ query : '"C:\\temp"' ,
91+ options : { } ,
92+ prisma,
93+ } ) ;
94+
95+ expect ( ir ) . toMatchObject ( {
96+ query : 'substring' ,
97+ substring : { pattern : 'C:\\temp' } ,
98+ } ) ;
99+ } ) ;
100+
75101 it ( 'unescapes a quoted content: value' , async ( ) => {
76102 const ir = await parseQuerySyntaxIntoIR ( {
77103 query : 'content:"say \\"hi\\""' ,
Original file line number Diff line number Diff line change @@ -72,12 +72,13 @@ const findLinguistLanguage = (value: string): string => {
7272}
7373
7474/**
75- * Quoted strings may contain backslash escapes (e.g. `\"`). Keyword search
76- * matches patterns literally, so the escapes are resolved here. In regex mode
77- * they are left in place for the regex engine to interpret.
75+ * Quoted strings may escape quotes, backslashes, and line terminators. Keyword
76+ * search matches patterns literally, so those escapes are resolved here. Other
77+ * backslashes remain literal (e.g. in Windows paths). In regex mode escapes
78+ * are left in place for the regex engine to interpret.
7879 */
7980const unescapeQuotedString = ( value : string ) : string => {
80- return value . replace ( / \\ ( . ) / g, '$1' ) ;
81+ return value . replace ( / \\ ( [ " \\ \r \n ] ) / g, '$1' ) ;
8182}
8283
8384/**
You can’t perform that action at this time.
0 commit comments