fix(auto-triage): avoid regex code fence parsing#3854
fix(auto-triage): avoid regex code fence parsing#3854kilo-code-bot[bot] wants to merge 1 commit into
Conversation
|
|
||
| while (lineStartIndex < text.length) { | ||
| const lineEndIndex = text.indexOf('\n', lineStartIndex); | ||
| const line = text.substring(lineStartIndex, lineEndIndex === -1 ? text.length : lineEndIndex); |
There was a problem hiding this comment.
WARNING: Windows \r\n line endings are not stripped — extracted JSON content will contain trailing \r on every line, breaking JSON.parse.
The old regex used \r?\n at both boundaries to strip carriage returns. Here, text.substring(..., lineEndIndex) keeps the \r before the \n, so when the extracted block content is passed to JSON.parse it will fail on Windows-generated or mixed-EOL text.
Fix: strip the trailing \r from each line:
| const line = text.substring(lineStartIndex, lineEndIndex === -1 ? text.length : lineEndIndex); | |
| const line = text.substring(lineStartIndex, lineEndIndex === -1 ? text.length : lineEndIndex).replace(/\r$/, ''); |
| const line = text.substring(lineStartIndex, lineEndIndex === -1 ? text.length : lineEndIndex); | ||
| const leadingWhitespaceLength = line.length - line.trimStart().length; | ||
|
|
||
| if (line.startsWith('```', leadingWhitespaceLength)) { |
There was a problem hiding this comment.
WARNING: The check line.startsWith('```', leadingWhitespaceLength) matches any line whose trimmed content begins with three backticks — including ```end, ```json, ``` some text, etc. This means a non-closing fence (e.g. a nested opening fence or an annotated fence) would be incorrectly treated as the closing fence, causing the block content to be truncated early.
The old regex implicitly required the closing fence to consist of only backticks (possibly with surrounding whitespace). The fix is to require the remainder of the line after the backticks to be empty:
| if (line.startsWith('```', leadingWhitespaceLength)) { | |
| if (line.trimStart().startsWith('```') && line.trimStart().slice(3).trim() === '') { |
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Executive SummaryThe linear fence scanner correctly eliminates the ReDoS risk but introduces two edge-case regressions: incorrect closing-fence detection on lines with trailing content, and loss of Overview
Issue Details (click to expand)WARNING
Files Reviewed (1 file)
Fix these issues in Kilo Cloud Reviewed by claude-4.6-sonnet-20260217 · 399,127 tokens Review guidance: REVIEW.md from base branch |
Summary
Verification
N/A; parser-only change with no manual UI flow.
Visual Changes
N/A
Reviewer Notes