fix: guard countMarkdownHeadings against non-string input#11882
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: guard countMarkdownHeadings against non-string input#11882roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
When a subtask returns to the main task, message.text can be a non-string truthy value (e.g. array or object). The existing falsy check (!text) lets these through, causing a TypeError on .replace(). Add a typeof check so non-string values safely return 0. Fixes #11881
10ac9ff to
dbc1d29
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #11879
Description
This PR attempts to address Issue #11879. When returning from a subtask to the parent task,
message.textcan be a non-string truthy value at runtime. The existingif (!text)guard incountMarkdownHeadings()only catches falsy values, so calling.replace()on a non-string throwsTypeError: n.replace is not a function.The fix adds a
typeof text !== "string"check to defensively handle non-string inputs, returning 0 instead of crashing.Changes:
webview-ui/src/utils/markdown.ts: Addedtypeofguard tocountMarkdownHeadingswebview-ui/src/utils/__tests__/markdown.spec.ts: Added test cases for non-string inputs (number, array, object, boolean)Feedback and guidance are welcome.
Test Procedure
countMarkdownHeadingsandhasComplexMarkdown, verifying they return 0/false instead of throwing.cd webview-ui && npx vitest run src/utils/__tests__/markdown.spec.tsPre-Submission Checklist
Screenshots / Videos
N/A (no UI changes)
Documentation Updates
Additional Notes
Minimal, defensive fix that prevents the crash without changing any upstream data flow.
Interactively review PR in Roo Code Cloud