fix(sms): trim prefixed phone number spacing (#111111)

Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
VectorPeak
2026-07-20 02:29:06 -07:00
committed by GitHub
co-authored by chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com> Peter Steinberger
parent 7defd4a7b4
commit 3ef2d8cf05
2 changed files with 8 additions and 1 deletions
+4
View File
@@ -9,14 +9,18 @@ import {
describe("SMS phone normalization", () => {
it("normalizes sms-prefixed E.164 phone numbers", () => {
expect(normalizeSmsPhoneNumber("sms:+1 (555) 123-4567")).toBe("+15551234567");
expect(normalizeSmsPhoneNumber("sms: +1 (555) 123-4567")).toBe("+15551234567");
expect(normalizeSmsPhoneNumber("twilio-sms:+1 (555) 123-4567")).toBe("+15551234567");
expect(normalizeSmsPhoneNumber("twilio-sms: +1 (555) 123-4567")).toBe("+15551234567");
expect(normalizeSmsAllowFrom("SMS:+44 20 7946 0958")).toBe("+442079460958");
expect(normalizeSmsAllowFrom("SMS: +44 20 7946 0958")).toBe("+442079460958");
expect(normalizeSmsAllowFrom("*")).toBe("*");
});
it("validates E.164-ish SMS targets", () => {
expect(looksLikeSmsPhoneNumber("+15551234567")).toBe(true);
expect(looksLikeSmsPhoneNumber("15551234567")).toBe(true);
expect(looksLikeSmsPhoneNumber("sms: +1 (555) 123-4567")).toBe(true);
expect(looksLikeSmsPhoneNumber("+01234567")).toBe(false);
expect(looksLikeSmsPhoneNumber("+1555")).toBe(false);
});
+4 -1
View File
@@ -1,6 +1,9 @@
// Sms plugin module implements phone behavior.
export function normalizeSmsPhoneNumber(raw: string): string {
const trimmed = raw.trim().replace(/^(?:sms|twilio-sms):/i, "");
const trimmed = raw
.trim()
.replace(/^(?:sms|twilio-sms):/i, "")
.trim();
if (!trimmed) {
return "";
}