Normalize attachment thread segments to lowercase

- Lowercase sanitized thread segments when creating attachment IDs
- Add coverage for mixed-case thread IDs in attachment store and projection pipeline tests
This commit is contained in:
Julius Marminge committed 2026-03-01 19:18:41 -08:00
1 parent afc0c78f0b
commit 39f07869d9
3 files changed
+12 -2

No files matched your search

+9
View File
@@ -34,6 +34,15 @@ describe("attachmentStore", () => {
expect(parseThreadSegmentFromAttachmentId(fooBarId)).toBe("foo-bar");
});
it("normalizes created thread segments to lowercase", () => {
const attachmentId = createAttachmentId("Thread.Foo");
expect(attachmentId).toBeTruthy();
if (!attachmentId) {
return;
}
expect(parseThreadSegmentFromAttachmentId(attachmentId)).toBe("thread-foo");
});
it("resolves attachment path by id using the extension that exists on disk", () => {
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "t3code-attachment-store-"));
try {
+1
View File
@@ -23,6 +23,7 @@ const ATTACHMENT_ID_PATTERN = new RegExp(
export function toSafeThreadAttachmentSegment(threadId: string): string | null {
const segment = threadId
.trim()
.toLowerCase()
.replace(/[^a-z0-9_-]+/gi, "-")
.replace(/-+/g, "-")
.replace(/^[-_]+|[-_]+$/g, "")
@@ -733,7 +733,7 @@ projectionLayer("OrchestrationProjectionPipeline", (it) => {
const projectionPipeline = yield* OrchestrationProjectionPipeline;
const eventStore = yield* OrchestrationEventStore;
const now = new Date().toISOString();
const threadId = ThreadId.makeUnsafe("thread revert.files");
const threadId = ThreadId.makeUnsafe("Thread Revert.Files");
const keepAttachmentId = "thread-revert-files-00000000-0000-4000-8000-000000000001";
const removeAttachmentId = "thread-revert-files-00000000-0000-4000-8000-000000000002";
const otherThreadAttachmentId =
@@ -948,7 +948,7 @@ projectionLayer("OrchestrationProjectionPipeline", (it) => {
const projectionPipeline = yield* OrchestrationProjectionPipeline;
const eventStore = yield* OrchestrationEventStore;
const now = new Date().toISOString();
const threadId = ThreadId.makeUnsafe("thread delete.files");
const threadId = ThreadId.makeUnsafe("Thread Delete.Files");
const attachmentId = "thread-delete-files-00000000-0000-4000-8000-000000000001";
const otherThreadAttachmentId =
"thread-delete-files-extra-00000000-0000-4000-8000-000000000002";