messagebird-nodejs
messagebird-nodejs copied to clipboard
URL-encode phone numbers so Lookup API can handle formats with spaces
The Lookup API can be used to parse and normalize phone numbers but it fails (with TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters) when the number contains spaces. Developers would have to URL-encode numbers, which is against the principle that an SDK should abstract HTTP details. This PR fixes that by URL-encoding within the SDK.
This does not yet support formats like XXXX/YYYYYYYY (with slashes) which are commonly used in some countries. URL-encoding should do the trick so this is probably a server-side issue?!
@LukasRos thanks for submitting a pull request! We'll have a look at this next week.
As for the /. I do indeed think this is a server-side issue, but I'm unsure whether that is something we'll be supporting in the near future. I've put it towards the responsible team, and they'll have a look.
Hi @LukasRos, thanks again - and sorry it took a little longer to get back to you. I definitely agree encoding query parameters is something a client/SDK should take care off.
I'd just like to point out that this change is backwards incompatible: users who have ran into this same issue may already be encoding the phone numbers on their end. Merging this as-is would result in them ending up with double encoded, and thus malformed, strings.
A simple and effective solution for this would be to first decode the provided string, and then encoding that result (e.g. encodeURIComponent(decodeURIComponent(phoneNumber))). What do you think? Also, it would be great to have some tests for this.
Thanks!