fix: prevent TypeError in countMarkdownHeadings for non-string input#11606
Draft
roomote[bot] wants to merge 1 commit intomainfrom
Draft
fix: prevent TypeError in countMarkdownHeadings for non-string input#11606roomote[bot] wants to merge 1 commit intomainfrom
roomote[bot] wants to merge 1 commit intomainfrom
Conversation
…ror on non-string input Fixes #11605. The existing guard `if (!text)` only catches falsy values. When a truthy non-string value (e.g. number or object from an API response) is passed through OpenMarkdownPreviewButton, it passes the guard and text.replace() throws "TypeError: n.replace is not a function". Changed the guard to `typeof text !== "string"` so any non-string value returns 0 early. Added test cases for non-string inputs.
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.
This PR attempts to address Issue #11605. Feedback and guidance are welcome.
Problem
countMarkdownHeadings()inwebview-ui/src/utils/markdown.tscrashes withTypeError: n.replace is not a functionwhen a non-string truthy value (e.g. a number or object from an API response) is passed throughOpenMarkdownPreviewButton. The existing guardif (!text)only catches falsy values, so truthy non-strings slip through.Fix
if (!text)toif (typeof text !== "string" || !text)so any non-string value returns 0 earlyTesting
webview-ui/src/utils/__tests__/markdown.spec.tsStart a new Roo Code Cloud session on this branch