Skip to content

Commit eb28b56

Browse files
committed
Correctly scope the validation check for file paths enclosed in single backticks to prevent misidentification within sentences
1 parent 3c19103 commit eb28b56

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,23 @@ export const parse_multiple_files = (params: {
186186
!potential_path.includes(' ') &&
187187
/[a-zA-Z0-9]/.test(potential_path)
188188
) {
189-
let is_followed_by_code_block = false
190-
for (let j = i + 1; j < lines.length; j++) {
191-
const next_line = lines[j].trim()
192-
if (next_line.startsWith('```')) {
193-
is_followed_by_code_block = true
194-
break
189+
const before = line.substring(0, match.index!)
190+
const after = line.substring(match.index! + match[0].length)
191+
192+
// Avoid matching file paths that are part of a sentence.
193+
if (!(/[a-zA-Z]/.test(before) && /[a-zA-Z]/.test(after))) {
194+
let is_followed_by_code_block = false
195+
for (let j = i + 1; j < lines.length; j++) {
196+
const next_line = lines[j].trim()
197+
if (next_line.startsWith('```')) {
198+
is_followed_by_code_block = true
199+
break
200+
}
195201
}
196-
}
197202

198-
if (is_followed_by_code_block) {
199-
extracted_filename = potential_path
203+
if (is_followed_by_code_block) {
204+
extracted_filename = potential_path
205+
}
200206
}
201207
}
202208
}

0 commit comments

Comments
 (0)