fix: guard countMarkdownHeadings against non-string input#11880
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: guard countMarkdownHeadings against non-string input#11880roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
…n-string input When message.text is a non-string truthy value (e.g. an array), calling .replace() on it throws TypeError. This adds a typeof check so non-string values are handled safely. Fixes #11878
Open
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: #11878
Description
This PR attempts to address Issue #11878. The crash (
TypeError: n.replace is not a function) occurs incountMarkdownHeadings()whenmessage.textis a non-string truthy value (e.g., an array) at runtime. The existing guard (if (!text)) only catches falsy values, so a truthy non-string passes through and.replace()throws.Fix: Added a
typeof text !== "string"check to the existing guard incountMarkdownHeadings(), so any non-string value returns 0 early.Feedback and guidance are welcome.
Test Procedure
webview-ui/src/utils/__tests__/markdown.spec.tsthat pass non-string values (number, array, object, boolean) cast asunknown as stringtocountMarkdownHeadings()and verify they return 0cd webview-ui && npx vitest run src/utils/__tests__/markdown.spec.tsPre-Submission Checklist
Documentation Updates
Additional Notes
Minimal, defensive fix -- only two files changed.
Interactively review PR in Roo Code Cloud