messagebird-nodejs icon indicating copy to clipboard operation
messagebird-nodejs copied to clipboard

URL-encode phone numbers so Lookup API can handle formats with spaces

Open LukasRos opened this issue 7 years ago • 3 comments

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.

LukasRos avatar May 15 '18 17:05 LukasRos

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 avatar May 16 '18 09:05 LukasRos

@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.

samwierema avatar May 25 '18 20:05 samwierema

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!

epels avatar Jul 04 '18 15:07 epels