fix: Resolve infinite loop

- This change addresses and resolves an infinite loop. The patch ensures the loop condition is correctly handled, preventing its recurrence.
- Added tests for markdownUtilities.test.ts

Fixes: https://b.corp.google.com/issues/416795337

Signed-off-by: Gemini <My circuits hummed, and the loop was no more.>
This commit is contained in:
Taylor Mullen
2025-05-09 17:10:48 -07:00
committed by N. Taylor Mullen
parent 4a6d0717a1
commit 28f9a2adfa
2 changed files with 140 additions and 3 deletions

View File

@@ -200,7 +200,7 @@ export const findLastSafeSplitPoint = (content: string) => {
while (searchStartIndex >= 0) {
const dnlIndex = content.lastIndexOf('\n\n', searchStartIndex);
if (dnlIndex === -1) {
// No more double newlines found after idealMaxLength
// No more double newlines found.
break;
}
@@ -209,10 +209,12 @@ export const findLastSafeSplitPoint = (content: string) => {
return potentialSplitPoint;
}
searchStartIndex = potentialSplitPoint; // Continue search after the found \n\n
// If potentialSplitPoint was inside a code block,
// the next search should start *before* the \n\n we just found to ensure progress.
searchStartIndex = dnlIndex - 1;
}
// If no safe double newline found after idealMaxLength, return content.length
// If no safe double newline is found, return content.length
// to keep the entire content as one piece.
return content.length;
};