Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/web/src/components/ChatMarkdown.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,23 @@ describe("ChatMarkdown favicon privacy", () => {
});
});

describe("ChatMarkdown external link labels", () => {
it("keeps a leading emoji whole", async () => {
setup();
await using screen = await render(
<ChatMarkdown cwd="/tmp/project" text="[😀 Read the documentation](https://example.com)" />,
);
await vi.waitFor(() => {
const link = screen.container.querySelector("a");
expect(link?.textContent).toContain("😀 Read");
const walker = document.createTreeWalker(link!, NodeFilter.SHOW_TEXT);
const textNodes: string[] = [];
while (walker.nextNode()) textNodes.push(walker.currentNode.nodeValue ?? "");
expect(textNodes.filter((node) => /\p{Surrogate}/u.test(node))).toEqual([]);
});
});
});

describe("ChatMarkdown streaming", () => {
it("runs only a complete single-line shell block after a click", async () => {
setup();
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/components/chat/MarkdownExternalLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const MarkdownLinkFavicon = memo(function MarkdownLinkFavicon({ host }: { host:
function leadingExternalLinkTextLength(text: string): number {
const protocol = /^(?:https?:\/\/)/i.exec(text)?.[0];
if (protocol) return protocol.length;
return Math.min(text.length, 1);
// A whole code point, so a surrogate pair is not split across elements.
return Array.from(text.slice(0, 2))[0]?.length ?? 0;
}

// Keep short labels such as PR numbers intact in narrow table columns.
Expand Down
Loading