Skip to content

Trust urns.ParsePhone for phone number parsing now that it's stricter #739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2024
Merged
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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

require (
github.com/antchfx/xmlquery v1.4.0
github.com/aws/aws-sdk-go v1.52.3
github.com/aws/aws-sdk-go v1.52.4
github.com/buger/jsonparser v1.1.1
github.com/dghubble/oauth1 v0.7.3
github.com/getsentry/sentry-go v0.27.0
Expand All @@ -16,7 +16,7 @@ require (
github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9
github.com/nyaruka/ezconf v0.3.0
github.com/nyaruka/gocommon v1.54.3
github.com/nyaruka/gocommon v1.54.4
github.com/nyaruka/null/v3 v3.0.0
github.com/nyaruka/redisx v0.8.0
github.com/patrickmn/go-cache v2.1.0+incompatible
Expand Down Expand Up @@ -48,7 +48,7 @@ require (
github.com/naoina/toml v0.1.1 // indirect
github.com/nyaruka/librato v1.1.1 // indirect
github.com/nyaruka/null/v2 v2.0.3 // indirect
github.com/nyaruka/phonenumbers v1.3.4 // indirect
github.com/nyaruka/phonenumbers v1.3.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/antchfx/xmlquery v1.4.0 h1:xg2HkfcRK2TeTbdb0m1jxCYnvsPaGY/oeZWTGqX/0h
github.com/antchfx/xmlquery v1.4.0/go.mod h1:Ax2aeaeDjfIw3CwXKDQ0GkwZ6QlxoChlIBP+mGnDFjI=
github.com/antchfx/xpath v1.3.0 h1:nTMlzGAK3IJ0bPpME2urTuFL76o4A96iYvoKFHRXJgc=
github.com/antchfx/xpath v1.3.0/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
github.com/aws/aws-sdk-go v1.52.3 h1:BNPJmHOXNoM/iBWJKrvaQvJOweRcp3KLpzdb65CfQwU=
github.com/aws/aws-sdk-go v1.52.3/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.52.4 h1:9VsBVJ2TKf8xPP3+yIPGSYcEBIEymXsJzQoFgQuyvA0=
github.com/aws/aws-sdk-go v1.52.4/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -71,16 +71,16 @@ github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8=
github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
github.com/nyaruka/ezconf v0.3.0 h1:kGvJqVN8AHowb4HdaHAviJ0Z3yI5Pyekp1WqibFEaGk=
github.com/nyaruka/ezconf v0.3.0/go.mod h1:89GUW6EPRNLIxT7lC4LWnjWTgZeQwRoX7lBmc8ralAU=
github.com/nyaruka/gocommon v1.54.3 h1:NZx2hdVRFfvxW9ug5RY7XTNkrqbXW0w+o9mB5lJtv84=
github.com/nyaruka/gocommon v1.54.3/go.mod h1:3rM5QdBU5YzFn/3KlDI0skPEghgssIS4WtLiji99JsA=
github.com/nyaruka/gocommon v1.54.4 h1:93JR8DmussPu3mukhcnfYWaHk6b7LiOw7dm0cR0pWaU=
github.com/nyaruka/gocommon v1.54.4/go.mod h1:rWkEIpYIK98zL9Qm6PeMXJ+84WcWlArf01RfuWWCYvQ=
github.com/nyaruka/librato v1.1.1 h1:0nTYtJLl3Sn7lX3CuHsLf+nXy1k/tGV0OjVxLy3Et4s=
github.com/nyaruka/librato v1.1.1/go.mod h1:fme1Fu1PT2qvkaBZyw8WW+SrnFe2qeeCWpvqmAaKAKE=
github.com/nyaruka/null/v2 v2.0.3 h1:rdmMRQyVzrOF3Jff/gpU/7BDR9mQX0lcLl4yImsA3kw=
github.com/nyaruka/null/v2 v2.0.3/go.mod h1:OCVeCkCXwrg5/qE6RU0c1oUVZBy+ZDrT+xYg1XSaIWA=
github.com/nyaruka/null/v3 v3.0.0 h1:JvOiNuKmRBFHxzZFt4sWii+ewmMkCQ1vO7X0clTNn6E=
github.com/nyaruka/null/v3 v3.0.0/go.mod h1:Sus286RmC8P0VihFuQDDQPib/xJQ7++TsaPLdRuwgVc=
github.com/nyaruka/phonenumbers v1.3.4 h1:bF1Wdh++fxw09s3surhVeBhXEcUKG07pHeP8HQXqjn8=
github.com/nyaruka/phonenumbers v1.3.4/go.mod h1:Ut+eFwikULbmCenH6InMKL9csUNLyxHuBLyfkpum11s=
github.com/nyaruka/phonenumbers v1.3.5 h1:WZLbQn61j2E1OFnvpUTYbK/6hViUgl6tppJ55/E2iQM=
github.com/nyaruka/phonenumbers v1.3.5/go.mod h1:Ut+eFwikULbmCenH6InMKL9csUNLyxHuBLyfkpum11s=
github.com/nyaruka/redisx v0.8.0 h1:5QSDLfHBRFjrlTD9VaxfBbq72rb0S++Dr2ui9q/q9kY=
github.com/nyaruka/redisx v0.8.0/go.mod h1:mpTqnydmHfzeQ8V55AwS/cVrkxzHu4yGvwClEeprvbA=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
Expand Down
3 changes: 2 additions & 1 deletion handlers/africastalking/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/buger/jsonparser"
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/urns"
)

const configIsShared = "is_shared"
Expand Down Expand Up @@ -68,7 +69,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
}

// create our URN
urn, err := handlers.StrictTelForCountry(form.From, channel.Country())
urn, err := urns.ParsePhone(form.From, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/bandwidth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/nyaruka/courier/utils"
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/jsonx"
"github.com/nyaruka/gocommon/urns"
)

var (
Expand Down Expand Up @@ -90,7 +91,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
}

// create our URN
urn, err := handlers.StrictTelForCountry(messagePayload.Message.From, channel.Country())
urn, err := urns.ParsePhone(messagePayload.Message.From, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/bongolive/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/gsm7"
"github.com/nyaruka/gocommon/urns"

"github.com/buger/jsonparser"
)
Expand Down Expand Up @@ -92,7 +93,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
clog.SetType(courier.ChannelLogTypeMsgReceive)

// create our URN
urn, err := handlers.StrictTelForCountry(form.From, channel.Country())
urn, err := urns.ParsePhone(form.From, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/clickatell/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/buger/jsonparser"
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/urns"
)

var (
Expand Down Expand Up @@ -123,7 +124,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
}

// create our URN
urn, err := handlers.StrictTelForCountry(payload.FromNumber, channel.Country())
urn, err := urns.ParsePhone(payload.FromNumber, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/clickmobile/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/dates"
"github.com/nyaruka/gocommon/jsonx"
"github.com/nyaruka/gocommon/urns"
)

var (
Expand Down Expand Up @@ -71,7 +72,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
}

// create our URN
urn, err := handlers.StrictTelForCountry(payload.Mobile, channel.Country())
urn, err := urns.ParsePhone(payload.Mobile, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/dart/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
}

// create our URN
urn, err := handlers.StrictTelForCountry(form.Original, channel.Country())
urn, err := urns.ParsePhone(form.Original, channel.Country())
if err != nil {
urn, err = urns.New(urns.External, form.Original)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion handlers/dmark/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/buger/jsonparser"
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/urns"
)

var (
Expand Down Expand Up @@ -61,7 +62,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
}

// create our URN
urn, err := handlers.StrictTelForCountry(form.MSISDN, channel.Country())
urn, err := urns.ParsePhone(form.MSISDN, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
4 changes: 2 additions & 2 deletions handlers/external/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (h *handler) receiveStopContact(ctx context.Context, channel courier.Channe
// create our URN
urn := urns.NilURN
if channel.Schemes()[0] == urns.Phone.Prefix {
urn, err = handlers.StrictTelForCountry(form.From, channel.Country())
urn, err = urns.ParsePhone(form.From, channel.Country())
} else {
urn = urns.URN(channel.Schemes()[0] + ":" + form.From)
err = urn.Validate()
Expand Down Expand Up @@ -203,7 +203,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
// create our URN
urn := urns.NilURN
if channel.Schemes()[0] == urns.Phone.Prefix {
urn, err = handlers.StrictTelForCountry(from, channel.Country())
urn, err = urns.ParsePhone(from, channel.Country())
} else {
urn = urns.URN(channel.Schemes()[0] + ":" + from)
err = urn.Validate()
Expand Down
3 changes: 2 additions & 1 deletion handlers/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"time"

"github.com/nyaruka/courier"
"github.com/nyaruka/gocommon/urns"
)

// NewTelReceiveHandler creates a new receive handler given the passed in text and from fields
Expand All @@ -23,7 +24,7 @@
return nil, WriteAndLogRequestError(ctx, h, c, w, r, fmt.Errorf("missing required field '%s'", fromField))
}
// create our URN
urn, err := StrictTelForCountry(from, c.Country())
urn, err := urns.ParsePhone(from, c.Country())

Check warning on line 27 in handlers/generic.go

View check run for this annotation

Codecov / codecov/patch

handlers/generic.go#L27

Added line #L27 was not covered by tests
if err != nil {
return nil, WriteAndLogRequestError(ctx, h, c, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/globe/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/urns"
)

var (
Expand Down Expand Up @@ -92,7 +93,7 @@ func (h *handler) receiveMessage(ctx context.Context, c courier.Channel, w http.
return nil, handlers.WriteAndLogRequestError(ctx, h, c, w, r, fmt.Errorf("invalid 'senderAddress' parameter"))
}

urn, err := handlers.StrictTelForCountry(glMsg.SenderAddress[4:], c.Country())
urn, err := urns.ParsePhone(glMsg.SenderAddress[4:], c.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, c, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/highconnection/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/urns"
)

var (
Expand Down Expand Up @@ -63,7 +64,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
}

// create our URN
urn, err := handlers.StrictTelForCountry(form.From, channel.Country())
urn, err := urns.ParsePhone(form.From, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/hormuud/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/gomodule/redigo/redis"
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/urns"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ func (h *handler) receiveMessage(ctx context.Context, c courier.Channel, w http.
return nil, handlers.WriteAndLogRequestError(ctx, h, c, w, r, err)
}

urn, err := handlers.StrictTelForCountry(payload.Sender, c.Country())
urn, err := urns.ParsePhone(payload.Sender, c.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, c, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/i2sms/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/urns"
)

const (
Expand Down Expand Up @@ -56,7 +57,7 @@ func (h *handler) receive(ctx context.Context, c courier.Channel, w http.Respons
}

// create our URN
urn, err := handlers.StrictTelForCountry(from, c.Country())
urn, err := urns.ParsePhone(from, c.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, c, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/infobip/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/urns"
)

var sendURL = "https://api.infobip.com/sms/1/text/advanced"
Expand Down Expand Up @@ -140,7 +141,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
}

// create our URN
urn, err := handlers.StrictTelForCountry(infobipMessage.From, channel.Country())
urn, err := urns.ParsePhone(infobipMessage.From, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/jasmin/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/gsm7"
"github.com/nyaruka/gocommon/urns"
)

var idRegex = regexp.MustCompile(`Success \"(.*)\"`)
Expand Down Expand Up @@ -82,7 +83,7 @@ func (h *handler) receiveMessage(ctx context.Context, c courier.Channel, w http.
}

// create our URN
urn, err := handlers.StrictTelForCountry(form.From, c.Country())
urn, err := urns.ParsePhone(form.From, c.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, c, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/justcall/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/jsonx"
"github.com/nyaruka/gocommon/urns"
)

var (
Expand Down Expand Up @@ -109,7 +110,7 @@ func (h *handler) receiveMessage(ctx context.Context, c courier.Channel, w http.
date = date.UTC()
}

urn, err := handlers.StrictTelForCountry(payload.Data.From, c.Country())
urn, err := urns.ParsePhone(payload.Data.From, c.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, c, w, r, err)
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/kannel/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
date := time.Unix(form.TS, 0).UTC()

// create our URN
urn, err := handlers.StrictTelForCountry(form.Sender, channel.Country())
urn, err := urns.ParsePhone(form.Sender, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/m3tech/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/gsm7"
"github.com/nyaruka/gocommon/urns"
)

var (
Expand Down Expand Up @@ -51,7 +52,7 @@ func (h *handler) receiveMessage(ctx context.Context, c courier.Channel, w http.
}

// create our URN
urn, err := handlers.StrictTelForCountry(from, c.Country())
urn, err := urns.ParsePhone(from, c.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, c, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/macrokiosk/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/gsm7"
"github.com/nyaruka/gocommon/urns"

"github.com/buger/jsonparser"
)
Expand Down Expand Up @@ -122,7 +123,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
}

// create our URN
urn, err := handlers.StrictTelForCountry(sender, channel.Country())
urn, err := urns.ParsePhone(sender, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
3 changes: 2 additions & 1 deletion handlers/mblox/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/nyaruka/courier"
"github.com/nyaruka/courier/handlers"
"github.com/nyaruka/gocommon/urns"
)

var (
Expand Down Expand Up @@ -90,7 +91,7 @@ func (h *handler) receiveEvent(ctx context.Context, channel courier.Channel, w h
}

// create our URN
urn, err := handlers.StrictTelForCountry(payload.From, channel.Country())
urn, err := urns.ParsePhone(payload.From, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/messagebird/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (h *handler) receiveMessage(ctx context.Context, channel courier.Channel, w
}

// create our URN
urn, err := handlers.StrictTelForCountry(payload.Originator, channel.Country())
urn, err := urns.ParsePhone(payload.Originator, channel.Country())
if err != nil {
return nil, handlers.WriteAndLogRequestError(ctx, h, channel, w, r, err)
}
Expand Down
Loading
Loading