@@ -7,9 +7,14 @@ import {
77} from '../clipboard-parser'
88import { parse_file_content_only } from './file-content-only-parser'
99
10- const extract_file_path_from_xml = ( line : string ) : string | null => {
11- const match = line . match ( / < f i l e \s + p a t h = [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / )
12- return match ? match [ 1 ] : null
10+ const extract_file_path_from_xml = (
11+ line : string
12+ ) : { tagName : string ; path : string } | null => {
13+ const match = line . match ( / < ( \w + ) \s + p a t h = [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / )
14+ if ( match && match [ 1 ] && match [ 2 ] ) {
15+ return { tagName : match [ 1 ] , path : match [ 2 ] }
16+ }
17+ return null
1318}
1419
1520export const parse_multiple_files = ( params : {
@@ -37,6 +42,7 @@ export const parse_multiple_files = (params: {
3742 let last_seen_file_path_comment : string | null = null
3843 let is_markdown_container_block = false
3944 let current_language = ''
45+ let current_xml_tag : string | null = null
4046
4147 const lines = params . response . split ( '\n' )
4248
@@ -136,18 +142,19 @@ export const parse_multiple_files = (params: {
136142 in_cdata = false
137143 is_markdown_container_block = false
138144 continue
139- } else if ( line . trim ( ) . startsWith ( '<file ' ) ) {
140- const extracted_filename = extract_file_path_from_xml ( line )
141- if ( extracted_filename ) {
145+ } else if ( line . trim ( ) . startsWith ( '<' ) ) {
146+ const xml_info = extract_file_path_from_xml ( line )
147+ if ( xml_info ) {
142148 if ( current_text_block . trim ( ) ) {
143149 results . push ( { type : 'text' , content : current_text_block . trim ( ) } )
144150 }
145151 current_text_block = ''
146152
147153 state = 'CONTENT'
154+ current_xml_tag = xml_info . tagName
148155 top_level_xml_file_mode = true
149156 const { workspace_name, relative_path } = extract_workspace_and_path ( {
150- raw_file_path : extracted_filename ,
157+ raw_file_path : xml_info . path ,
151158 is_single_root_folder_workspace :
152159 params . is_single_root_folder_workspace
153160 } )
@@ -228,7 +235,7 @@ export const parse_multiple_files = (params: {
228235 }
229236 } else if ( state == 'CONTENT' ) {
230237 if ( top_level_xml_file_mode ) {
231- if ( line . trim ( ) . startsWith ( '</file>' ) ) {
238+ if ( line . trim ( ) . startsWith ( `</ ${ current_xml_tag } >` ) ) {
232239 let final_content = current_content . trim ( )
233240 const content_lines = final_content . split ( '\n' )
234241 if (
@@ -265,6 +272,7 @@ export const parse_multiple_files = (params: {
265272 current_workspace_name = undefined
266273 top_level_xml_file_mode = false
267274 in_cdata = false
275+ current_xml_tag = null
268276 } else if ( line . trim ( ) . startsWith ( '<![CDATA[' ) ) {
269277 in_cdata = true
270278 } else if ( in_cdata && line . trim ( ) . includes ( ']]>' ) ) {
@@ -386,12 +394,12 @@ export const parse_multiple_files = (params: {
386394 current_text_block = line . substring ( last_backticks_index + 3 )
387395 }
388396 } else {
389- if ( is_first_content_line && line . trim ( ) . startsWith ( '<file ' ) ) {
390- const extracted_filename = extract_file_path_from_xml ( line )
391- if ( extracted_filename ) {
397+ if ( is_first_content_line && line . trim ( ) . startsWith ( '<' ) ) {
398+ const xml_info = extract_file_path_from_xml ( line )
399+ if ( xml_info ) {
392400 const { workspace_name, relative_path } =
393401 extract_workspace_and_path ( {
394- raw_file_path : extracted_filename ,
402+ raw_file_path : xml_info . path ,
395403 is_single_root_folder_workspace :
396404 params . is_single_root_folder_workspace
397405 } )
@@ -400,6 +408,7 @@ export const parse_multiple_files = (params: {
400408 current_workspace_name = workspace_name
401409 }
402410 xml_file_mode = true
411+ current_xml_tag = xml_info . tagName
403412 is_first_content_line = false
404413 continue
405414 }
@@ -531,7 +540,11 @@ export const parse_multiple_files = (params: {
531540 continue
532541 }
533542
534- if ( xml_file_mode && ! in_cdata && line . trim ( ) == '</file>' ) {
543+ if (
544+ xml_file_mode &&
545+ ! in_cdata &&
546+ line . trim ( ) == `</${ current_xml_tag } >`
547+ ) {
535548 continue
536549 }
537550
0 commit comments