Skip to content

Commit 4f0e5a6

Browse files
committed
Improve file path detection in code blocks by applying stricter character validation to uncommented paths
1 parent 82f509a commit 4f0e5a6

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

  • packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,12 @@ export const parse_multiple_files = (params: {
383383
extracted_filename = extract_path_from_line_of_code(line)
384384
} else {
385385
// Heuristic for uncommented file path
386-
const last_segment = trimmed_line
387-
.replace(/\\/g, '/')
388-
.split('/')
389-
.pop()
386+
const potential_path = trimmed_line.replace(/\\/g, '/')
387+
const last_segment = potential_path.split('/').pop()
390388
if (
391389
last_segment?.includes('.') &&
392-
!/[(){};,=[\]]/.test(trimmed_line)
390+
!last_segment?.endsWith('.') &&
391+
/^[a-zA-Z0-9_./@-]+$/.test(potential_path)
393392
) {
394393
extracted_filename = trimmed_line
395394
}

0 commit comments

Comments
 (0)