Skip to content

Commit d6df54e

Browse files
committed
Refactor file parsing logic to correctly handle and extract file content when XML file tags are not explicitly closed, treating subsequent text as regular content
1 parent 7271e3b commit d6df54e

8 files changed

Lines changed: 192 additions & 119 deletions

File tree

‎1-file.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("hello")

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,30 @@ describe('clipboard-parser', () => {
161161
})
162162
})
163163

164+
it('parses file when file-xml content is wrapped in its own markdown code block but the file tag is not closed', () => {
165+
const test_case = 'file-xml-inner-code-block-unclosed'
166+
const text = load_test_case_file(test_case, `${test_case}.txt`)
167+
const result = parse_multiple_files({
168+
response: text,
169+
is_single_root_folder_workspace: true
170+
})
171+
172+
expect(result).toHaveLength(3)
173+
expect(result[0]).toMatchObject({
174+
type: 'text',
175+
content: load_test_case_file(test_case, '1-text.txt')
176+
})
177+
expect(result[1]).toMatchObject({
178+
type: 'file',
179+
file_path: 'src/index.ts',
180+
content: load_test_case_file(test_case, '2-file.txt')
181+
})
182+
expect(result[2]).toMatchObject({
183+
type: 'text',
184+
content: load_test_case_file(test_case, '3-text.txt')
185+
})
186+
})
187+
164188
it('parses file when file path is in an HTML-style comment inside a code block', () => {
165189
const test_case = 'html-comment-style'
166190
const text = load_test_case_file(test_case, `${test_case}.txt`)

0 commit comments

Comments
 (0)