fix(imessage): normalize messaging targets (#1708)
Co-authored-by: Aaron Ng <1653630+aaronn@users.noreply.github.com>
This commit is contained in:
@@ -28,6 +28,27 @@ describe("imessage targets", () => {
|
||||
expect(normalizeIMessageHandle(" +1 (555) 222-3333 ")).toBe("+15552223333");
|
||||
});
|
||||
|
||||
it("normalizes chat_id prefixes case-insensitively", () => {
|
||||
expect(normalizeIMessageHandle("CHAT_ID:123")).toBe("chat_id:123");
|
||||
expect(normalizeIMessageHandle("Chat_Id:456")).toBe("chat_id:456");
|
||||
expect(normalizeIMessageHandle("chatid:789")).toBe("chat_id:789");
|
||||
expect(normalizeIMessageHandle("CHAT:42")).toBe("chat_id:42");
|
||||
});
|
||||
|
||||
it("normalizes chat_guid prefixes case-insensitively", () => {
|
||||
expect(normalizeIMessageHandle("CHAT_GUID:abc-def")).toBe("chat_guid:abc-def");
|
||||
expect(normalizeIMessageHandle("ChatGuid:XYZ")).toBe("chat_guid:XYZ");
|
||||
expect(normalizeIMessageHandle("GUID:test-guid")).toBe("chat_guid:test-guid");
|
||||
});
|
||||
|
||||
it("normalizes chat_identifier prefixes case-insensitively", () => {
|
||||
expect(normalizeIMessageHandle("CHAT_IDENTIFIER:iMessage;-;chat123")).toBe(
|
||||
"chat_identifier:iMessage;-;chat123",
|
||||
);
|
||||
expect(normalizeIMessageHandle("ChatIdentifier:test")).toBe("chat_identifier:test");
|
||||
expect(normalizeIMessageHandle("CHATIDENT:foo")).toBe("chat_identifier:foo");
|
||||
});
|
||||
|
||||
it("checks allowFrom against chat_id", () => {
|
||||
const ok = isAllowedIMessageSender({
|
||||
allowFrom: ["chat_id:9"],
|
||||
|
||||
@@ -34,6 +34,27 @@ export function normalizeIMessageHandle(raw: string): string {
|
||||
if (lowered.startsWith("imessage:")) return normalizeIMessageHandle(trimmed.slice(9));
|
||||
if (lowered.startsWith("sms:")) return normalizeIMessageHandle(trimmed.slice(4));
|
||||
if (lowered.startsWith("auto:")) return normalizeIMessageHandle(trimmed.slice(5));
|
||||
|
||||
// Normalize chat_id/chat_guid/chat_identifier prefixes case-insensitively
|
||||
for (const prefix of CHAT_ID_PREFIXES) {
|
||||
if (lowered.startsWith(prefix)) {
|
||||
const value = trimmed.slice(prefix.length).trim();
|
||||
return `chat_id:${value}`;
|
||||
}
|
||||
}
|
||||
for (const prefix of CHAT_GUID_PREFIXES) {
|
||||
if (lowered.startsWith(prefix)) {
|
||||
const value = trimmed.slice(prefix.length).trim();
|
||||
return `chat_guid:${value}`;
|
||||
}
|
||||
}
|
||||
for (const prefix of CHAT_IDENTIFIER_PREFIXES) {
|
||||
if (lowered.startsWith(prefix)) {
|
||||
const value = trimmed.slice(prefix.length).trim();
|
||||
return `chat_identifier:${value}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (trimmed.includes("@")) return trimmed.toLowerCase();
|
||||
const normalized = normalizeE164(trimmed);
|
||||
if (normalized) return normalized;
|
||||
|
||||
Reference in New Issue
Block a user