mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-06 02:47:56 +00:00
Merge 0600b3f62a into 2bb826039b
This commit is contained in:
commit
cddfc05d85
2 changed files with 11 additions and 1 deletions
|
|
@ -8,6 +8,16 @@ describe("markdown heading helpers", () => {
|
||||||
expect(countMarkdownHeadings("")).toBe(0)
|
expect(countMarkdownHeadings("")).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("returns 0 for non-string values", () => {
|
||||||
|
// These simulate runtime scenarios where a non-string truthy value
|
||||||
|
// is passed due to unexpected API data (see issue #11605)
|
||||||
|
expect(countMarkdownHeadings(42 as unknown as string)).toBe(0)
|
||||||
|
expect(countMarkdownHeadings({ key: "value" } as unknown as string)).toBe(0)
|
||||||
|
expect(countMarkdownHeadings(["# heading"] as unknown as string)).toBe(0)
|
||||||
|
expect(countMarkdownHeadings(true as unknown as string)).toBe(0)
|
||||||
|
expect(countMarkdownHeadings(null as unknown as string)).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
it("counts single and multiple headings", () => {
|
it("counts single and multiple headings", () => {
|
||||||
expect(countMarkdownHeadings("# One")).toBe(1)
|
expect(countMarkdownHeadings("# One")).toBe(1)
|
||||||
expect(countMarkdownHeadings("# One\nContent")).toBe(1)
|
expect(countMarkdownHeadings("# One\nContent")).toBe(1)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
* Code fences are stripped before matching to avoid false positives.
|
* Code fences are stripped before matching to avoid false positives.
|
||||||
*/
|
*/
|
||||||
export function countMarkdownHeadings(text: string | undefined): number {
|
export function countMarkdownHeadings(text: string | undefined): number {
|
||||||
if (!text) return 0
|
if (typeof text !== "string" || !text) return 0
|
||||||
|
|
||||||
// Remove fenced code blocks to avoid counting headings inside code
|
// Remove fenced code blocks to avoid counting headings inside code
|
||||||
const withoutCodeBlocks = text.replace(/```[\s\S]*?```/g, "")
|
const withoutCodeBlocks = text.replace(/```[\s\S]*?```/g, "")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue