Skip to content

Commit 0364b74

Browse files
miorbnliclaude
andcommitted
fix(msteams): route HTML text extraction through normalizeContentType
extractTextFromHtmlAttachments guarded its loop with an exact `attachment.contentType !== "text/html"` check, which is the same case-sensitivity gap the rest of the PR closes via normalizeContentType. A mixed-case "TEXT/HTML" attachment (common from Teams relays; MIME types are case-insensitive per RFC 2045) was skipped, so a message whose only body text lived in such an HTML attachment entered the agent path with empty text. Route the guard through normalizeContentType so mixed-case HTML attachments reach the body extractor. Export the function and add regression coverage for mixed-case / whitespace-padded / object-content / non-HTML cases. Co-Authored-By: Claude <[email protected]>
1 parent caede8a commit 0364b74

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Msteams tests cover mixed-case HTML attachment content-type handling.
2+
import { describe, expect, it } from "vitest";
3+
import { extractTextFromHtmlAttachments } from "./message-handler.js";
4+
5+
describe("extractTextFromHtmlAttachments mixed-case content type", () => {
6+
// MIME types are case-insensitive (RFC 2045); a relay payload may emit
7+
// "TEXT/HTML" and the message handler must still extract its body text.
8+
it("extracts text from a mixed-case TEXT/HTML attachment", () => {
9+
const result = extractTextFromHtmlAttachments([
10+
{ contentType: "TEXT/HTML", content: "<p>Hello Teams</p>" },
11+
]);
12+
expect(result).toBe("Hello Teams");
13+
});
14+
15+
it("extracts text from a lowercase text/html attachment (regression)", () => {
16+
const result = extractTextFromHtmlAttachments([
17+
{ contentType: "text/html", content: "<p>Hello Teams</p>" },
18+
]);
19+
expect(result).toBe("Hello Teams");
20+
});
21+
22+
it("returns empty when no HTML attachment is present", () => {
23+
const result = extractTextFromHtmlAttachments([
24+
{ contentType: "application/vnd.microsoft.card.hero", content: {} },
25+
]);
26+
expect(result).toBe("");
27+
});
28+
29+
it("extracts from the first HTML attachment with usable text", () => {
30+
const result = extractTextFromHtmlAttachments([
31+
{ contentType: "Text/Html", content: "<p>First</p>" },
32+
{ contentType: "text/html", content: "<p>Second</p>" },
33+
]);
34+
expect(result).toBe("First");
35+
});
36+
37+
it("extracts body text from an attachment with a { text } content object", () => {
38+
const result = extractTextFromHtmlAttachments([
39+
{ contentType: "TEXT/HTML", content: { text: "<p>Object body</p>" } },
40+
]);
41+
expect(result).toBe("Object body");
42+
});
43+
});

‎extensions/msteams/src/monitor-handler/message-handler.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
summarizeMSTeamsHtmlAttachments,
2929
type MSTeamsAttachmentLike,
3030
} from "../attachments.js";
31-
import { isRecord } from "../attachments/shared.js";
31+
import { isRecord, normalizeContentType } from "../attachments/shared.js";
3232
import { tryNormalizeBotFrameworkServiceUrl } from "../bot-framework-service-url.js";
3333
import type { StoredConversationReference } from "../conversation-store.js";
3434
import { formatUnknownError } from "../errors.js";
@@ -56,9 +56,12 @@ import {
5656
summarizeParentMessage,
5757
} from "../thread-parent-context.js";
5858

59-
function extractTextFromHtmlAttachments(attachments: MSTeamsAttachmentLike[]): string {
59+
// Exported for tests asserting mixed-case HTML content-type handling.
60+
export function extractTextFromHtmlAttachments(attachments: MSTeamsAttachmentLike[]): string {
6061
for (const attachment of attachments) {
61-
if (attachment.contentType !== "text/html") {
62+
// MIME types are case-insensitive (RFC 2045); normalize before comparing so a
63+
// mixed-case "TEXT/HTML" attachment still reaches the HTML body extraction.
64+
if (normalizeContentType(attachment.contentType) !== "text/html") {
6265
continue;
6366
}
6467
const content = attachment.content;

0 commit comments

Comments
 (0)