mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 18:41:48 +00:00
fix(markdown): normalize non-finite render chunk limits
This commit is contained in:
@@ -70,4 +70,17 @@ describe("renderMarkdownIRChunksWithinLimit", () => {
|
||||
|
||||
expect(chunks.map((chunk) => chunk.source.text)).toEqual(["README.md", "<"]);
|
||||
});
|
||||
|
||||
it("normalizes non-finite limits before chunking", () => {
|
||||
const ir = markdownToIR("abc");
|
||||
const chunks = renderMarkdownIRChunksWithinLimit({
|
||||
ir,
|
||||
limit: Number.NaN,
|
||||
renderChunk: renderEscapedHtml,
|
||||
measureRendered: (rendered) => rendered.length,
|
||||
});
|
||||
|
||||
expect(chunks.map((chunk) => chunk.source.text)).toEqual(["a", "b", "c"]);
|
||||
expect(chunks.every((chunk) => chunk.rendered.length <= 1)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { resolveIntegerOption } from "../shared/number-coercion.js";
|
||||
import {
|
||||
chunkMarkdownIR,
|
||||
sliceMarkdownIR,
|
||||
@@ -30,7 +31,7 @@ export function renderMarkdownIRChunksWithinLimit<TRendered>(
|
||||
return [];
|
||||
}
|
||||
|
||||
const normalizedLimit = Math.max(1, Math.floor(options.limit));
|
||||
const normalizedLimit = resolveIntegerOption(options.limit, 1, { min: 1 });
|
||||
const pending = chunkMarkdownIR(options.ir, normalizedLimit);
|
||||
const finalized: MarkdownIR[] = [];
|
||||
|
||||
@@ -196,7 +197,7 @@ function splitMarkdownIRPreserveWhitespace(ir: MarkdownIR, limit: number): Markd
|
||||
return [];
|
||||
}
|
||||
|
||||
const normalizedLimit = Math.max(1, Math.floor(limit));
|
||||
const normalizedLimit = resolveIntegerOption(limit, 1, { min: 1 });
|
||||
if (normalizedLimit <= 0 || ir.text.length <= normalizedLimit) {
|
||||
return [ir];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user