@@ -145,7 +145,7 @@ Detailed commit message with multiple lines
145145 expect ( result ) . toContain ( `Error fetching commit info: ${ errorMessage } ` )
146146 } )
147147
148- it ( "should parse file paths with spaces" , async ( ) => {
148+ it ( "should parse file paths with escaped spaces" , async ( ) => {
149149 // Mock the file content fetching
150150 const fileContent = "This is the content of the file with spaces in its name"
151151
@@ -155,8 +155,8 @@ Detailed commit message with multiple lines
155155 jest . spyOn ( fs , "readFile" ) . mockResolvedValue ( fileContent )
156156 jest . spyOn ( fs , "stat" ) . mockResolvedValue ( { isFile : ( ) => true , isDirectory : ( ) => false } as any )
157157
158- // Test with a file path containing spaces
159- const filePath = "/path/with spaces/my file.txt"
158+ // Test with a file path containing escaped spaces
159+ const filePath = "/path/with\\ spaces/my\\ file.txt"
160160
161161 // First, verify that the regex pattern correctly matches the entire path
162162 // Import the regex pattern directly to test it
@@ -168,14 +168,14 @@ Detailed commit message with multiple lines
168168 // Now test the full parseMentions function
169169 const result = await parseMentions ( `Check out this file @${ filePath } ` , mockCwd , mockUrlContentFetcher )
170170
171- // Verify the file path with spaces was correctly parsed
171+ // Verify the file path with escaped spaces was correctly parsed
172+ // The spaces should be unescaped when displayed
172173 expect ( result ) . toContain ( `'path/with spaces/my file.txt' (see below for file content)` )
173174 expect ( result ) . toContain ( `<file_content path="path/with spaces/my file.txt">` )
174175 } )
175176
176- it ( "should parse folder paths with spaces" , async ( ) => {
177+ it ( "should parse folder paths with escaped spaces" , async ( ) => {
177178 // Mock the folder content fetching
178- const folderContent = "├── file1.txt\n├── file2.txt\n└── subfolder/"
179179
180180 // Mock the getFileOrFolderContent function (which is called internally by parseMentions)
181181 // This is done by mocking the fs.readdir and fs.stat that would be called inside getFileOrFolderContent
@@ -187,13 +187,48 @@ Detailed commit message with multiple lines
187187 ] )
188188 jest . spyOn ( fs , "stat" ) . mockResolvedValue ( { isFile : ( ) => false , isDirectory : ( ) => true } as any )
189189
190- const folderPath = "/folder with spaces/"
190+ // Test with a folder path containing escaped spaces
191+ const folderPath = "/folder\\ with\\ spaces/"
192+
193+ // First, verify that the regex pattern correctly matches the entire path
194+ const { mentionRegexGlobal } = require ( "../../../shared/context-mentions" )
195+ const mentionMatch = `@${ folderPath } ` . match ( mentionRegexGlobal )
196+ expect ( mentionMatch ) . not . toBeNull ( )
197+ expect ( mentionMatch ! [ 0 ] ) . toBe ( `@${ folderPath } ` )
198+
191199 const result = await parseMentions ( `Check out this folder @${ folderPath } ` , mockCwd , mockUrlContentFetcher )
192200
193- // Verify the folder path with spaces was correctly parsed
201+ // Verify the folder path with escaped spaces was correctly parsed
202+ // The spaces should be unescaped when displayed
194203 expect ( result ) . toContain ( `'folder with spaces/' (see below for folder content)` )
195204 expect ( result ) . toContain ( `<folder_content path="folder with spaces/">` )
196205 } )
206+
207+ it ( "should parse nested paths with multiple escaped spaces" , async ( ) => {
208+ // Mock the file content fetching
209+ const fileContent = "This is the content of the file with multiple spaces in its path"
210+
211+ // Mock the getFileOrFolderContent function
212+ const fs = require ( "fs/promises" )
213+ jest . spyOn ( fs , "readFile" ) . mockResolvedValue ( fileContent )
214+ jest . spyOn ( fs , "stat" ) . mockResolvedValue ( { isFile : ( ) => true , isDirectory : ( ) => false } as any )
215+
216+ // Test with a deeply nested path containing multiple escaped spaces
217+ const filePath = "/root\\ dir/my\\ documents/project\\ files/important\\ notes/final\\ draft\\ v2.txt"
218+
219+ // Verify the regex pattern correctly matches the entire path
220+ const { mentionRegexGlobal } = require ( "../../../shared/context-mentions" )
221+ const mentionMatch = `@${ filePath } ` . match ( mentionRegexGlobal )
222+ expect ( mentionMatch ) . not . toBeNull ( )
223+ expect ( mentionMatch ! [ 0 ] ) . toBe ( `@${ filePath } ` )
224+
225+ // Test the full parseMentions function
226+ const result = await parseMentions ( `Check out this file @${ filePath } ` , mockCwd , mockUrlContentFetcher )
227+
228+ // Verify the complex path was correctly parsed with all spaces unescaped
229+ expect ( result ) . toContain ( `'root dir/my documents/project files/important notes/final draft v2.txt' (see below for file content)` )
230+ expect ( result ) . toContain ( `<file_content path="root dir/my documents/project files/important notes/final draft v2.txt">` )
231+ } )
197232 } )
198233
199234 describe ( "openMention" , ( ) => {
0 commit comments