Skip to content

Commit 28c85da

Browse files
committed
Normalize file paths by stripping leading slashes during clipboard parsing
1 parent 91e15d8 commit 28c85da

5 files changed

Lines changed: 18 additions & 28 deletions

File tree

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/clipboard-parser.spec.ts‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,6 @@ describe('clipboard-parser', () => {
148148
)
149149
})
150150

151-
it('should parse html comment with leading slash in path', () => {
152-
const text = load_test_case_file(
153-
'html-comment-leading-slash',
154-
'html-comment-leading-slash.txt'
155-
)
156-
const result = parse_multiple_files({
157-
response: text,
158-
is_single_root_folder_workspace: true
159-
})
160-
161-
expect(result).toHaveLength(1)
162-
expect(result[0].file_path).toBe('src/index.js')
163-
expect(result[0].content).toBe(
164-
load_test_case_file('html-comment-leading-slash', 'file-1.txt')
165-
)
166-
})
167-
168151
it('should handle workspace prefixes', () => {
169152
const text = load_test_case_file(
170153
'with-workspace-prefix',

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/clipboard-parser.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ export const extract_workspace_and_path = (
2727
raw_file_path: string,
2828
is_single_root_folder_workspace: boolean
2929
): { workspace_name?: string; relative_path: string } => {
30-
const file_path = raw_file_path.replace(/\\/g, '/')
30+
let file_path = raw_file_path.replace(/\\/g, '/')
31+
if (file_path.startsWith('/')) {
32+
file_path = file_path.substring(1)
33+
}
3134
if (is_single_root_folder_workspace || !file_path.includes('/')) {
3235
return { relative_path: file_path }
3336
}
@@ -256,6 +259,19 @@ export const parse_multiple_files = (params: {
256259
}
257260
}
258261
let extracted_filename = extract_path_from_line_of_code(line)
262+
if (!extracted_filename) {
263+
const trimmed = line.trim()
264+
if (trimmed.startsWith('<!--') && trimmed.endsWith('-->')) {
265+
const potential_path = trimmed.slice(4, -3).trim()
266+
if (
267+
potential_path.includes('/') ||
268+
potential_path.includes('\\') ||
269+
potential_path.includes('.')
270+
) {
271+
extracted_filename = potential_path
272+
}
273+
}
274+
}
259275
if (!extracted_filename) {
260276
const match = line.match(/`([^`]+)`/)
261277
if (match && match[1]) {

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/test-cases/html-comment-filename-outside-code-block/html-comment-filename-outside-code-block.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Lorem ipsum. This text should be ignored.
88

99
This is another part of the response that should be ignored.
1010

11-
<!-- src/lorem.css -->
11+
<!--/src/lorem.css-->
1212
```css
1313
.ipsum {}
1414
```

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/test-cases/html-comment-leading-slash/file-1.txt‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/test-cases/html-comment-leading-slash/html-comment-leading-slash.txt‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)