Skip to content

The open-source app everyone uses to manage agents at work

fix(issues): normalize HTML entities in @mention tokens before agent lookup (#1255)

Paperclip Dev47449152acfe
diff --git a/server/src/__tests__/normalize-agent-mention-token.test.ts b/server/src/__tests__/normalize-agent-mention-token.test.ts
new file mode 100644
index 0000000000..786e484d4d
--- /dev/null
+++ b/server/src/__tests__/normalize-agent-mention-token.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, it } from "vitest";
+import { normalizeAgentMentionToken } from "../services/issues.ts";
+
+describe("normalizeAgentMentionToken", () => {
+ it("strips hex numeric entities such as space ( )", () => {
+ expect(normalizeAgentMentionToken("Baba ")).toBe("Baba");
+ });
+
+ it("strips decimal numeric entities", () => {
+ expect(normalizeAgentMentionToken("Baba ")).toBe("Baba");
+ });
+
+ it("strips common named entities", () => {
+ expect(normalizeAgentMentionToken("Baba ")).toBe("Baba");
+ });
+
+ it("returns plain names unchanged", () => {
+ expect(normalizeAgentMentionToken("Baba")).toBe("Baba");
+ });
+
+ it("trims after stripping entities", () => {
+ expect(normalizeAgentMentionToken("Baba  ")).toBe("Baba");
+ });
+});
diff --git a/server/src/services/issues.ts b/server/src/services/issues.ts
index 1f1a49619f..610f932558 100644
--- a/server/src/services/issues.ts
+++ b/server/src/services/issues.ts
@@ -196,6 +196,13 @@ function unreadForUserCondition(companyId: string, userId: string) {
`;
}
+const HTML_ENTITY_IN_MENTION = /&#x[0-9a-fA-F]+;|&#[0-9]+;|&[a-z]+;/gi;
+
+/** Strips common HTML entities from a raw @mention capture so UI-encoded bodies still match agent names. */
+export function normalizeAgentMentionToken(raw: string): string {
+ return raw.replace(HTML_ENTITY_IN_MENTION, "").trim();
+}
+
export function deriveIssueUserContext(
issue: IssueUserContextInput,
userId: string,
@@ -1446,7 +1453,10 @@ export function issueService(db: Db) {
const re = /\B@([^\s@,!?.]+)/g;
const tokens = new Set<string>();
let m: RegExpExecArray | null;
- while ((m = re.exec(body)) !== null) tokens.add(m[1].toLowerCase());
+ while ((m = re.exec(body)) !== null) {
+ const normalized = normalizeAgentMentionToken(m[1]);
+ if (normalized) tokens.add(normalized.toLowerCase());
+ }
if (tokens.size === 0) return [];
const rows = await db.select({ id: agents.id, name: agents.name })
.from(agents).where(eq(agents.companyId, companyId));