Skip to content

Commit 15e4fbf

Browse files
authored
fix(markdown-core): treat infinity chunk limit as unbounded
Fix render-aware markdown chunking so `Number.POSITIVE_INFINITY` is treated as an explicit unbounded chunk limit instead of falling back to `1`. This preserves full Signal media captions and disabled Signal text chunking while keeping invalid non-finite limits on the existing fallback path. Fixes #92734. Thanks @yhterrance for the report and fix.
1 parent 4e4ea1c commit 15e4fbf

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

extensions/signal/src/format.chunking.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,16 @@ describe("splitSignalFormattedText", () => {
296296
});
297297

298298
describe("markdownToSignalTextChunks", () => {
299+
it("treats Infinity as unbounded for media captions", () => {
300+
const markdown = "Here's **another** photo from today's walk.";
301+
302+
const chunks = markdownToSignalTextChunks(markdown, Number.POSITIVE_INFINITY);
303+
304+
expect(chunks).toHaveLength(1);
305+
expect(chunks[0]?.text).toBe("Here's another photo from today's walk.");
306+
expect(chunks[0]?.styles.map((style) => style.style)).toContain("BOLD");
307+
});
308+
299309
describe("link expansion chunk limit", () => {
300310
it("does not exceed chunk limit after link expansion", () => {
301311
// Create text that is close to limit, with a link that will expand

packages/markdown-core/src/render-aware-chunking.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,18 @@ describe("renderMarkdownIRChunksWithinLimit", () => {
8484
expect(chunks.map((chunk) => chunk.source.text)).toEqual(["a", "b", "c"]);
8585
expect(chunks.every((chunk) => chunk.rendered.length <= 1)).toBe(true);
8686
});
87+
88+
it("treats Infinity as no size cap and returns a single chunk", () => {
89+
const text = "one two three four five six seven eight nine ten";
90+
const ir = markdownToIR(text);
91+
const chunks = renderMarkdownIRChunksWithinLimit({
92+
ir,
93+
limit: Number.POSITIVE_INFINITY,
94+
renderChunk: renderEscapedHtml,
95+
measureRendered: (rendered) => rendered.length,
96+
});
97+
98+
expect(chunks).toHaveLength(1);
99+
expect(chunks[0]?.source.text).toBe(text);
100+
});
87101
});

packages/markdown-core/src/render-aware-chunking.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export function renderMarkdownIRChunksWithinLimit<TRendered>(
4747
return [];
4848
}
4949

50+
// Callers pass Infinity to mean "no size cap" (e.g. a media caption that must not be
51+
// split). resolveIntegerOption rejects non-finite values and would fall back to 1,
52+
// shattering the text into one chunk per character; emit the whole IR as one chunk.
53+
if (options.limit === Number.POSITIVE_INFINITY) {
54+
return [{ source: options.ir, rendered: options.renderChunk(options.ir) }];
55+
}
56+
5057
const normalizedLimit = resolveIntegerOption(options.limit, 1, { min: 1 });
5158
const pending = chunkMarkdownIR(options.ir, normalizedLimit);
5259
const finalized: MarkdownIR[] = [];

0 commit comments

Comments
 (0)