fix(slack): guard against undefined text in includes calls during mention handling
This commit is contained in:
parent
ce4faedad6
commit
2a98fd3d0b
20
src/auto-reply/reply/mentions.test.ts
Normal file
20
src/auto-reply/reply/mentions.test.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { stripStructuralPrefixes } from "./mentions.js";
|
||||||
|
|
||||||
|
describe("stripStructuralPrefixes", () => {
|
||||||
|
it("returns empty string for undefined input at runtime", () => {
|
||||||
|
expect(stripStructuralPrefixes(undefined as unknown as string)).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns empty string for empty input", () => {
|
||||||
|
expect(stripStructuralPrefixes("")).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("strips sender prefix labels", () => {
|
||||||
|
expect(stripStructuralPrefixes("John: hello")).toBe("hello");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("passes through plain text", () => {
|
||||||
|
expect(stripStructuralPrefixes("just a message")).toBe("just a message");
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -111,6 +111,9 @@ export function matchesMentionWithExplicit(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function stripStructuralPrefixes(text: string): string {
|
export function stripStructuralPrefixes(text: string): string {
|
||||||
|
if (!text) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
// Ignore wrapper labels, timestamps, and sender prefixes so directive-only
|
// Ignore wrapper labels, timestamps, and sender prefixes so directive-only
|
||||||
// detection still works in group batches that include history/context.
|
// detection still works in group batches that include history/context.
|
||||||
const afterMarker = text.includes(CURRENT_MESSAGE_MARKER)
|
const afterMarker = text.includes(CURRENT_MESSAGE_MARKER)
|
||||||
|
|||||||
@ -57,6 +57,10 @@ describe("markdownToSlackMrkdwn", () => {
|
|||||||
"*Important:* Check the _docs_ at <https://example.com|link>\n\n• first\n• second",
|
"*Important:* Check the _docs_ at <https://example.com|link>\n\n• first\n• second",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not throw when input is undefined at runtime", () => {
|
||||||
|
expect(markdownToSlackMrkdwn(undefined as unknown as string)).toBe("");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("escapeSlackMrkdwn", () => {
|
describe("escapeSlackMrkdwn", () => {
|
||||||
|
|||||||
@ -28,6 +28,9 @@ function isAllowedSlackAngleToken(token: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function escapeSlackMrkdwnContent(text: string): string {
|
function escapeSlackMrkdwnContent(text: string): string {
|
||||||
|
if (!text) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
if (!text.includes("&") && !text.includes("<") && !text.includes(">")) {
|
if (!text.includes("&") && !text.includes("<") && !text.includes(">")) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
@ -53,6 +56,9 @@ function escapeSlackMrkdwnContent(text: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function escapeSlackMrkdwnText(text: string): string {
|
function escapeSlackMrkdwnText(text: string): string {
|
||||||
|
if (!text) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
if (!text.includes("&") && !text.includes("<") && !text.includes(">")) {
|
if (!text.includes("&") && !text.includes("<") && !text.includes(">")) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user