fix(matrix): ignore filename-embedded mxids · openclaw/openclaw@5574f75
vincentkoc
·
2026-05-27
·
via Recent Commits to openclaw:main
File tree
extensions/matrix/src/matrix
| Original file line number | Diff line number | Diff line change |
|---|
@@ -211,6 +211,18 @@ describe("markdownToMatrixHtml", () => {
|
211 | 211 | expect(result.mentions).toStrictEqual({}); |
212 | 212 | }); |
213 | 213 | |
| 214 | +it("does not emit mentions for filename-embedded mxids with trailing hyphens", async () => { |
| 215 | +const result = await renderMarkdownToMatrixHtmlWithMentions({ |
| 216 | +markdown: "read matrix-progress-@room-@alice:matrix-qa.test-!room:matrix-qa.test.txt", |
| 217 | +client: createMentionClient(), |
| 218 | +}); |
| 219 | + |
| 220 | +expect(result.html).toBe( |
| 221 | +"<p>read matrix-progress-@room-@alice:matrix-qa.test-!room:matrix-qa.test.txt</p>", |
| 222 | +); |
| 223 | +expect(result.mentions).toStrictEqual({}); |
| 224 | +}); |
| 225 | + |
214 | 226 | it("accepts bracketed homeservers in matrix mentions", async () => { |
215 | 227 | const result = await renderMarkdownToMatrixHtmlWithMentions({ |
216 | 228 | markdown: "hello @alice:[2001:db8::1]", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -32,8 +32,11 @@ type MatrixMentionCandidate = {
|
32 | 32 | |
33 | 33 | const ESCAPED_MENTION_SENTINEL = "\uE000"; |
34 | 34 | const MENTION_PATTERN = /@[A-Za-z0-9._=+\-/:[\]]+/g; |
35 | | -const MATRIX_MENTION_USER_ID_PATTERN = |
36 | | -/^@[A-Za-z0-9._=+\-/]+:(?:[A-Za-z0-9.-]+|\[[0-9A-Fa-f:.]+\])(?::\d+)?$/; |
| 35 | +const MATRIX_MENTION_SERVER_NAME_PATTERN = |
| 36 | +/(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)(?:\.(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?))*(?::\d+)?/; |
| 37 | +const MATRIX_MENTION_USER_ID_PATTERN = new RegExp( |
| 38 | +`^@[A-Za-z0-9._=+\\-/]+:(?:${MATRIX_MENTION_SERVER_NAME_PATTERN.source}|\\[[0-9A-Fa-f:.]+\\](?::\\d+)?)$`, |
| 39 | +); |
37 | 40 | const TRIMMABLE_MENTION_SUFFIX = /[),.!?:;\]]/; |
38 | 41 | |
39 | 42 | function shouldSuppressAutoLink( |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -761,6 +761,23 @@ describe("sendSingleTextMessageMatrix", () => {
|
761 | 761 | expect(formattedBody).not.toContain("matrix.to"); |
762 | 762 | }); |
763 | 763 | |
| 764 | +it("does not activate filename-embedded Matrix mentions in normal text", async () => { |
| 765 | +const { client, sendMessage } = makeClient(); |
| 766 | + |
| 767 | +await sendSingleTextMessageMatrix( |
| 768 | +"room:!room:example", |
| 769 | +"read matrix-progress-@room-@alice:matrix-qa.test-!room:matrix-qa.test.txt failed", |
| 770 | +{ |
| 771 | + client, |
| 772 | +cfg: {} as never, |
| 773 | +}, |
| 774 | +); |
| 775 | + |
| 776 | +const content = sentContent(sendMessage); |
| 777 | +expect(content["m.mentions"]).toEqual({}); |
| 778 | +expect((content as { formatted_body?: string }).formatted_body).not.toContain("matrix.to"); |
| 779 | +}); |
| 780 | + |
764 | 781 | it("merges extra content fields into single-event sends", async () => { |
765 | 782 | const { client, sendMessage } = makeClient(); |
766 | 783 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。