Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions sdks/js/agent-sdk/src/util/AttachmentUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ describe("AttachmentUtil", () => {

expect(remoteAttachment.url).toBe(testUrl);
expect(remoteAttachment.filename).toBe(fileName);
// Issue #4034: scheme must not carry the trailing colon that
// URL.protocol includes (e.g. "https", not "https:"), matching the
// format used elsewhere in libxmtp's remote attachment tests/examples.
expect(remoteAttachment.scheme).toBe("https");

const receivedAttachment =
await downloadRemoteAttachment(remoteAttachment);
Expand All @@ -97,4 +101,30 @@ describe("AttachmentUtil", () => {
expect(decryptedContent).toBe(fileContent);
});
});

describe("createRemoteAttachment scheme normalization", () => {
it("strips the trailing colon from URL.protocol (issue #4034)", async () => {
const fileContent = "scheme normalization test";
const unencryptedFile = new File([fileContent], "hello.txt", {
type: "text/plain",
});
const arrayBuffer = await unencryptedFile.arrayBuffer();
const encryptedAttachment = encryptAttachment({
filename: unencryptedFile.name,
content: new Uint8Array(arrayBuffer),
mimeType: unencryptedFile.type,
});

for (const [fileUrl, expectedScheme] of [
["https://localhost/test_file", "https"],
["http://localhost/test_file", "http"],
] as const) {
const remoteAttachment = createRemoteAttachment(
encryptedAttachment,
fileUrl,
);
expect(remoteAttachment.scheme).toBe(expectedScheme);
}
});
});
});
2 changes: 1 addition & 1 deletion sdks/js/agent-sdk/src/util/AttachmentUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function createRemoteAttachment(
filename: encryptedAttachment.filename,
nonce: encryptedAttachment.nonce,
salt: encryptedAttachment.salt,
scheme: url.protocol,
scheme: url.protocol.replace(/:$/, ""),
secret: encryptedAttachment.secret,
url: url.toString(),
};
Expand Down
Loading