mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-15 23:31:04 +00:00
Merge 121e1956e0 into c3cae397a1
This commit is contained in:
commit
aff2397c4a
2 changed files with 10 additions and 1 deletions
|
|
@ -8,6 +8,15 @@ describe("markdown heading helpers", () => {
|
|||
expect(countMarkdownHeadings("")).toBe(0)
|
||||
})
|
||||
|
||||
it("returns 0 for non-string values", () => {
|
||||
// At runtime, message.text can be a non-string truthy value (e.g. array)
|
||||
// which would cause .replace() to throw. The guard should handle this.
|
||||
expect(countMarkdownHeadings(42 as unknown as string)).toBe(0)
|
||||
expect(countMarkdownHeadings(["# heading"] as unknown as string)).toBe(0)
|
||||
expect(countMarkdownHeadings({} as unknown as string)).toBe(0)
|
||||
expect(countMarkdownHeadings(true as unknown as string)).toBe(0)
|
||||
})
|
||||
|
||||
it("counts single and multiple headings", () => {
|
||||
expect(countMarkdownHeadings("# One")).toBe(1)
|
||||
expect(countMarkdownHeadings("# One\nContent")).toBe(1)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
* Code fences are stripped before matching to avoid false positives.
|
||||
*/
|
||||
export function countMarkdownHeadings(text: string | undefined): number {
|
||||
if (!text) return 0
|
||||
if (!text || typeof text !== "string") return 0
|
||||
|
||||
// Remove fenced code blocks to avoid counting headings inside code
|
||||
const withoutCodeBlocks = text.replace(/```[\s\S]*?```/g, "")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue