Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): escape an HTML link label once its tags are gone
marcoteb30ef3f1f736a
diff --git a/mcp-host/src/workflow/__tests__/inlineMarkup.test.ts b/mcp-host/src/workflow/__tests__/inlineMarkup.test.tsindex a59b89d8b..6d91688b8 100644--- a/mcp-host/src/workflow/__tests__/inlineMarkup.test.ts+++ b/mcp-host/src/workflow/__tests__/inlineMarkup.test.ts@@ -195,6 +195,9 @@ describe('inline markdown', () => {'\\*x\\*','path\\to','\[1]',+ '<span>C:\\Users\\</span>',+ 'a\\<u>]</u> b',+ 'x\\<b>\\</b>',]for (const label of labels) {const outside = inlineSpans(label)diff --git a/mcp-host/src/workflow/inlineMarkup.ts b/mcp-host/src/workflow/inlineMarkup.tsindex d7e321f1e..21860602c 100644--- a/mcp-host/src/workflow/inlineMarkup.ts+++ b/mcp-host/src/workflow/inlineMarkup.ts@@ -283,11 +283,12 @@ function withPlaceholdersKept(text: string): string {/*** `label` as the text of a markdown link. A bracket, or a backslash that ends- * the label, is escaped so it prints instead of ending the label; an escape the- * label already holds is kept whole, so it prints as it does outside a link.+ * the label or stands before a style mark, is escaped so it prints instead of+ * ending the label; an escape the label already holds is kept whole, so it+ * prints as it does outside a link.*/function linkLabel(label: string): string {- return label.replace(/\\[\s\S]?|[[\]]/g, m => (m.length === 2 ? m : `\\${m}`))+ return label.replace(/\\[^\uFDD0-\uFDEF]?|[[\]]/g, m => (m.length === 2 ? m : `\\${m}`))}function htmlSegmentToMarkdown(text: string): string {@@ -297,14 +298,16 @@ function htmlSegmentToMarkdown(text: string): string {)return separate(separate(html, BLOCK_EDGE, '\n'), CELL_EDGE, ' ').replace(IMG_TAG, imageMarkdown)- .replace(ANCHOR, (_whole: string, tag: string, label: string) => {- const href = HREF.exec(tag)?.[1]- return href ? `[${linkLabel(label)}](${href})` : label- }).replace(BOLD_TAG, tag => styleMark('bold', tag)).replace(ITALIC_TAG, tag => styleMark('italics', tag)).replace(CODE_TAG, '`').replace(STRIKE_TAG, tag => styleMark('strike', tag))+ .replace(ANCHOR, (_whole: string, tag: string, label: string) => {+ const href = HREF.exec(tag)?.[1]+ // The label is escaped without its tags, so each backslash is read beside+ // the character that follows it in the printed text.+ return href ? `[${linkLabel(label.replace(HTML_TAG, ''))}](${href})` : label+ }).replace(HTML_TAG, '')}