mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 02:06:43 +00:00
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:
co-authored by
chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Peter Steinberger
parent
7defd4a7b4
commit
3ef2d8cf05
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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 "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user