Skip to content

Commit 7b87dc5

Browse files
committed
fix: correct URL handling in MarkdownBlock and add tests for trailing punctuation
1 parent 6798836 commit 7b87dc5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

webview-ui/src/components/common/MarkdownBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const remarkUrlToLink = () => {
4545
children.push({
4646
type: "link",
4747
url: cleanedMatches[i],
48-
children: [{ type: "text", value: cleanedMatches[i] }],
48+
children: [{ type: "text", value: matches[i] }],
4949
})
5050
}
5151
})
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from "react"
2+
import { render, screen } from "@testing-library/react"
3+
import MarkdownBlock from "../MarkdownBlock"
4+
import { vi } from "vitest"
5+
6+
vi.mock("@src/utils/vscode", () => ({
7+
vscode: {
8+
postMessage: vi.fn(),
9+
},
10+
}))
11+
12+
vi.mock("@src/context/ExtensionStateContext", () => ({
13+
useExtensionState: () => ({
14+
theme: "dark",
15+
}),
16+
}))
17+
18+
describe("MarkdownBlock", () => {
19+
it("should correctly handle URLs with trailing punctuation", async () => {
20+
const markdown = "Check out this link: https://example.com."
21+
render(<MarkdownBlock markdown={markdown} />)
22+
23+
await (async () => {
24+
const linkElement = screen.getByRole("link")
25+
expect(linkElement).toHaveAttribute("href", "https://example.com")
26+
expect(linkElement.textContent).toBe("https://example.com.")
27+
})
28+
})
29+
})

0 commit comments

Comments
 (0)