twilio / twilio-java

A Java library for communicating with the Twilio REST API and generating TwiML.
MIT License
491 stars 430 forks source link

NumberFetcher is double encoding the number #793

Open paulotaylor opened 6 months ago

paulotaylor commented 6 months ago

Issue Summary

com.twilio.rest.pricing.v2.voice.NumberFetcher is double encoding de number If I use the number +15017122661 we can see in the logs that it's trying to fetch %252B15017122661 which is the number +15017122661 url encoded twice As seen in the logs: request URL: https://pricing.twilio.com/v2/Voice/Numbers/%252B15017122661

Steps to Reproduce

Happens all the time when trying to fetch number pricing

Code Snippet

Number result = Number.fetcher(new PhoneNumber("+15017122661")).fetch();

Exception/Log

2024-04-30T15:04:35.310+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : -- BEGIN Twilio API Request --
2024-04-30T15:04:35.310+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : request method: GET
2024-04-30T15:04:35.310+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : request URL: https://pricing.twilio.com/v2/Voice/Numbers/%252B15017122661
2024-04-30T15:04:35.310+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : -- END Twilio API Request --
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : status code: 404
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : response headers:
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Date: Tue, 30 Apr 2024 14:04:35 GMT
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Content-Type: application/json
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Content-Length: 168
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Connection: keep-alive
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Access-Control-Allow-Origin: *
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Access-Control-Allow-Headers: Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Idempotency-Key
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Access-Control-Allow-Credentials: true
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Access-Control-Expose-Headers: ETag
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Twilio-Request-Id: RQ408349452393e60ea717e057c804fe81
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Twilio-Request-Duration: 0.012
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: Twilio-Concurrent-Requests: 1
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: X-Shenanigans: none
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: X-Powered-By: AT-5000
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: X-Home-Region: us1
2024-04-30T15:04:35.957+01:00 DEBUG 33882 --- [nio-8080-exec-3] com.twilio.http.TwilioRestClient         : responseHeader: X-API-Domain: pricing.twilio.com

Technical details:

tiwarishubham635 commented 6 months ago

I have reproduced this issue. The encoding is happening at two places:

  1. First one here at the API level
  2. Second one here at the request level

I can look into this and see if we can remove one of them. Thanks for pointing out.

bhaskar16 commented 1 week ago

@tiwarishubham635 Are you working on this? If not, I can take this up. Thanks.