π OpenHands: AI-Driven Development
fix: render literal angle-bracket text in user messages (#1481)
Vasco Schiavo886a7eeb571a
diff --git a/__tests__/components/chat-message.test.tsx b/__tests__/components/chat-message.test.tsxindex 7005a9eaf7..5980223ce0 100644--- a/__tests__/components/chat-message.test.tsx+++ b/__tests__/components/chat-message.test.tsx@@ -193,4 +193,41 @@ describe("ChatMessage", () => {expect(onStop).toHaveBeenCalledTimes(1);});++ it("renders a literal angle-bracket user message as visible text", () => {+ // Regression: user messages were rendered with raw-HTML parsing enabled,+ // so a message like "<something>" was parsed as an unknown HTML tag and+ // dropped by rehype-sanitize β leaving an empty bubble that looked like+ // nothing was sent. User input must render literally.+ const { container } = render(+ <ChatMessage type="user" message="<something>" />,+ );++ expect(screen.getByTestId("user-message")).toBeInTheDocument();+ // The angle-bracket text must survive verbatim...+ expect(container.textContent).toContain("<something>");+ // ...and must NOT have been parsed into an element.+ expect(container.querySelector("something")).toBeNull();+ });++ it("renders literal angle-bracket text in a sending user message", () => {+ // The pending/sending bubble renders through a different branch than the+ // settled message, so it gets its own guard.+ const { container } = render(+ <ChatMessage type="user" message="<something>" pendingStatus="sending" />,+ );++ expect(container.textContent).toContain("<something>");+ expect(container.querySelector("something")).toBeNull();+ });++ it("still parses inline HTML for agent messages", () => {+ // The fix is scoped to user input: agent output keeps raw-HTML parsing so+ // allowed inline tags (badges, <mark>, <details>, β¦) continue to render.+ const { container } = render(+ <ChatMessage type="agent" message="Hello <mark>world</mark>" />,+ );++ expect(container.querySelector("mark")?.textContent).toBe("world");+ });});diff --git a/src/components/features/chat/chat-message.tsx b/src/components/features/chat/chat-message.tsxindex 2d5f2ade67..781b54c20f 100644--- a/src/components/features/chat/chat-message.tsx+++ b/src/components/features/chat/chat-message.tsx@@ -126,6 +126,7 @@ export function ChatMessage({<MarkdownRendererincludeStandardincludeHeadings+ allowHtml={type !== "user"}components={chatBubbleMarkdownComponents}>{message}diff --git a/src/components/features/chat/user-message-body.tsx b/src/components/features/chat/user-message-body.tsxindex 00e6b0a7c1..1fb1bfa21e 100644--- a/src/components/features/chat/user-message-body.tsx+++ b/src/components/features/chat/user-message-body.tsx@@ -80,6 +80,7 @@ export function UserMessageBody({<MarkdownRendererincludeStandardincludeHeadings+ allowHtml={false}components={chatBubbleMarkdownComponents}>{message}