Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): keep brackets in the label of an HTML link
marcoteb76d538b0790b
diff --git a/mcp-host/src/workflow/__tests__/inlineMarkup.test.ts b/mcp-host/src/workflow/__tests__/inlineMarkup.test.tsindex dd00851ea..79bd972b7 100644--- a/mcp-host/src/workflow/__tests__/inlineMarkup.test.ts+++ b/mcp-host/src/workflow/__tests__/inlineMarkup.test.ts@@ -172,6 +172,17 @@ describe('inline markdown', () => {expect(inlineSpans('Math 5 * 3 * 2 = 30')).toEqual([{ text: 'Math 5 * 3 * 2 = 30' }])})+ it('keeps brackets in the label of an HTML link', () => {+ expect(inlineSpans('Source <a href="https://x.com/a">[1]</a> end')).toEqual([+ { text: 'Source ' },+ { text: '[1]', link: 'https://x.com/a' },+ { text: ' end' },+ ])+ expect(inlineSpans('[a \\] b](https://x.com/b)')).toEqual([+ { text: 'a ] b', link: 'https://x.com/b' },+ ])+ })+it('keeps balanced parentheses in a link target', () => {expect(inlineSpans('[wiki](https://en.wikipedia.org/wiki/Foo_(bar)) end')).toEqual([{ text: 'wiki', link: 'https://en.wikipedia.org/wiki/Foo_(bar)' },@@ -279,6 +290,7 @@ describe('hostile input', () => {imageGroups: `'.repeat(60000)}`,imageGroupsRepeated: `'.repeat(5)}`.repeat(10000),link: '[a](http://x'.repeat(16000),+ linkEscapes: `[${'\\]'.repeat(100000)}`,bracket: '['.repeat(200000),bold: '**a '.repeat(50000),boldItalic: '***a '.repeat(40000),diff --git a/mcp-host/src/workflow/inlineMarkup.ts b/mcp-host/src/workflow/inlineMarkup.tsindex c50f39dad..ead0422f2 100644--- a/mcp-host/src/workflow/inlineMarkup.ts+++ b/mcp-host/src/workflow/inlineMarkup.ts@@ -260,7 +260,8 @@ function htmlSegmentToMarkdown(text: string): string {.replace(IMG_TAG, imageMarkdown).replace(ANCHOR, (_whole: string, tag: string, label: string) => {const href = HREF.exec(tag)?.[1]- return href ? `[${label}](${href})` : label+ // Brackets in the label are escaped, so they print instead of ending it.+ return href ? `[${label.replace(/[[\]]/g, '\\$&')}](${href})` : label}).replace(BOLD_TAG, tag => styleMark('bold', tag)).replace(ITALIC_TAG, tag => styleMark('italics', tag))@@ -379,7 +380,7 @@ export function quoteParagraphs(lines: string[]): string[] {const ATOM = new RegExp([/!\[[^[\]\n]*\]\((?:[^()\n]|\([^()\n]*\))*\)/.source,- /\[[^[\]\n]+\]\((?:https?:\/\/|mailto:)(?:[^\s()]|\([^\s()]*\))+\)/.source,+ /\[(?:[^[\]\n\\]|\\.)+\]\((?:https?:\/\/|mailto:)(?:[^\s()]|\([^\s()]*\))+\)/.source,/`[^`]+`/.source,ESCAPE.source,].join('|'),