diff options
| author | Taylor Mullen <[email protected]> | 2025-05-09 17:10:48 -0700 |
|---|---|---|
| committer | N. Taylor Mullen <[email protected]> | 2025-05-09 17:37:36 -0700 |
| commit | 28f9a2adfaab7f92db408575833189a64e2b65de (patch) | |
| tree | 23908e454ae6181430574b5aa3449daefb9e6c1f /packages/cli/src/ui/utils/markdownUtilities.ts | |
| parent | 4a6d0717a12cd992e0d81c74d96ab4a850494117 (diff) | |
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.>
Diffstat (limited to 'packages/cli/src/ui/utils/markdownUtilities.ts')
| -rw-r--r-- | packages/cli/src/ui/utils/markdownUtilities.ts | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/packages/cli/src/ui/utils/markdownUtilities.ts b/packages/cli/src/ui/utils/markdownUtilities.ts index 96c2ba39..4ddb2285 100644 --- a/packages/cli/src/ui/utils/markdownUtilities.ts +++ b/packages/cli/src/ui/utils/markdownUtilities.ts @@ -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; }; |
