Fix quadratic conversation fence parsing (C-015) - #39
Conversation
Replace the ReDoS-prone fence regex in parseSegments with a linear line-based scan (C-015) and memoize parse on ConversationMessage. Co-authored-by: Nick Misasi <nick13misasi@gmail.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d87c03215
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| function isFenceCloser(line: string): boolean { | ||
| return line.trim() === '```'; |
There was a problem hiding this comment.
Match the closing fence length to the opener
When an assistant uses a valid four-or-more-backtick fence—commonly needed to show triple backticks inside the code—isFenceOpener accepts it via startsWith('```'), but a matching delimiter is rejected here because the closer must be exactly three backticks. Consequently close remains -1 and the entire fenced block renders as plain text; record the opening run length and accept a closing run of at least that length.
Useful? React with 👍 / 👎.


Summary
parseSegmentswith a linear, line-based scanner.```+ a long line with no closer) is now O(n) plain text instead of Θ(n²) regex backtracking.ConversationMessagememoizes parse results onmessage.text.Fixes teamsecure C-015 on the RHS dashboard branch. Stacked on #35.
Testing
npm test -- --watchAll=false src/utils/segments.test.ts(7/7, 200k-char case ~1ms)npm test -- --watchAll=false(102/102)npm run check-typesRelease Note