@@ -1282,7 +1282,8 @@ ${fileContents}`);
12821282 const jsonResult = await findRelevantFiles (
12831283 initialPrompt ,
12841284 paths ,
1285- fileContents
1285+ fileContents ,
1286+ currentScan ?. codeStructure // 添加代码结构信息
12861287 ) ;
12871288 const parsedResult = parseFilePathsResult ( jsonResult ) ;
12881289 const responseIndexedFiles = parsedResult . relevant_paths ;
@@ -1959,16 +1960,26 @@ ${fileContents}`);
19591960 return `__CODE_BLOCK_${ codeBlocks . length - 1 } __` ;
19601961 } ) ;
19611962
1963+ // 转义HTML标签,防止它们被直接渲染
1964+ processed = processed . replace ( / < / g, "<" ) . replace ( / > / g, ">" ) ;
1965+
19621966 // 然后处理单行反引号,使其可点击并显示气泡提示
19631967 let keywordCounter = 0 ;
19641968 processed = processed . replace ( / ` ( [ ^ ` ] + ) ` / g, ( match , keyword ) => {
19651969 const id = `keyword-${ keywordCounter ++ } ` ;
1966- return `<span id="${ id } " class="font-bold text-blue-600 dark:text-blue-400 underline cursor-pointer hover:bg-blue-100 dark:hover:bg-blue-900/30 px-0.5 rounded transition-colors" data-keyword="${ keyword } " data-tooltip-id="${ id } -tooltip" data-tooltip-content="加载中...">${ keyword } </span><div id="${ id } -tooltip" class="keyword-tooltip" style="display:none;"></div>` ;
1970+ // 确保关键词内部的HTML标签不会被错误解析
1971+ const escapedKeyword = keyword
1972+ . replace ( / & l t ; / g, "&lt;" )
1973+ . replace ( / & g t ; / g, "&gt;" ) ;
1974+ return `<span id="${ id } " class="font-bold text-blue-600 dark:text-blue-400 underline cursor-pointer hover:bg-blue-100 dark:hover:bg-blue-900/30 px-0.5 rounded transition-colors" data-keyword="${ escapedKeyword } " data-tooltip-id="${ id } -tooltip" data-tooltip-content="加载中...">${ escapedKeyword } </span><div id="${ id } -tooltip" class="keyword-tooltip" style="display:none;"></div>` ;
19671975 } ) ;
19681976
1969- // 最后,恢复代码块
1977+ // 最后,恢复代码块(但确保代码块内的内容正确转义)
19701978 codeBlocks . forEach ( ( block , index ) => {
1971- processed = processed . replace ( `__CODE_BLOCK_${ index } __` , block ) ;
1979+ processed = processed . replace (
1980+ `__CODE_BLOCK_${ index } __` ,
1981+ block . replace ( / & l t ; / g, "<" ) . replace ( / & g t ; / g, ">" )
1982+ ) ;
19721983 } ) ;
19731984
19741985 return processed ;
0 commit comments