Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): break PDF words joined by no-break spaces in linear time
marcoteb7374525c9849
diff --git a/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.ts b/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.tsindex 9ce3d45c0..6a7a4392c 100644--- a/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.ts@@ -710,6 +710,14 @@ describe('PDF input that would stall the host', () => {expect(pastMargin(pages)).toEqual([])}, 60_000)+ it('lays out a long run of words joined by no-break spaces', async () => {+ const started = performance.now()+ const { pages } = await render({ filename: 'nb.pdf', body: 'a\u00a0'.repeat(20_000) })+ expect(performance.now() - started).toBeLessThan(budgetMs)+ expect(allText(pages).match(/a/g)).toHaveLength(20_000)+ expect(pastMargin(pages)).toEqual([])+ }, 60_000)+it('lays out a huge title, company name and footer', async () => {const started = performance.now()const { result } = await render({diff --git a/mcp-host/src/workflow/pdfText.ts b/mcp-host/src/workflow/pdfText.tsindex 4f0af6dae..4f29a20e3 100644--- a/mcp-host/src/workflow/pdfText.ts+++ b/mcp-host/src/workflow/pdfText.ts@@ -55,9 +55,13 @@ export const LINE_FILL = 0.94*/const LONG_WORD = 64-/** Characters pdfmake may break a line after without a space: ideographs and CJK punctuation. */+/**+ * Characters pdfmake may break a line after: breaking spaces, ideographs and CJK+ * punctuation. No-break spaces (U+00A0, U+2007, U+202F, U+FEFF) are left out,+ * since pdfmake keeps the words they join on one line.+ */const BREAKS_AFTER =- /[\s\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\u3000-\u303F\uFF00-\uFFEF]/u+ /[\t\n\v\f\r \u1680\u2000-\u2006\u2008-\u200A\u2028\u2029\u205F\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\u3000-\u303F\uFF00-\uFFEF]/u/** Combining marks, which stay on the line of the character they follow. */const MARK = /^[\p{Mn}\p{Me}]$/u