Skip to content
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

fix: Add URI encoding for phone numbers #494

Merged
merged 1 commit into from
Nov 15, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public PhoneNumber fetch(final TwilioRestClient client) {
Request request = new Request(
HttpMethod.GET,
Domains.LOOKUPS.toString(),
"/v1/PhoneNumbers/" + this.pathPhoneNumber + "",
"/v1/PhoneNumbers/" + this.pathPhoneNumber.encode("utf-8") + "",
client.getRegion()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Number fetch(final TwilioRestClient client) {
Request request = new Request(
HttpMethod.GET,
Domains.PRICING.toString(),
"/v1/Voice/Numbers/" + this.pathNumber + "",
"/v1/Voice/Numbers/" + this.pathNumber.encode("utf-8") + "",
client.getRegion()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Number fetch(final TwilioRestClient client) {
Request request = new Request(
HttpMethod.GET,
Domains.PRICING.toString(),
"/v2/Voice/Numbers/" + this.pathDestinationNumber + "",
"/v2/Voice/Numbers/" + this.pathDestinationNumber.encode("utf-8") + "",
client.getRegion()
);

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/twilio/type/PhoneNumber.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.twilio.type;

import java.util.Objects;
import java.net.URLEncoder;

public class PhoneNumber implements Endpoint {
private final String rawNumber;
Expand Down Expand Up @@ -36,4 +37,13 @@ public int hashCode() {
public String toString() {
return this.rawNumber;
}

public String encode(String enc) {
try {
return URLEncoder.encode(this.rawNumber, enc);
}
catch (Exception e) {
return this.rawNumber;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testFetchRequest() {
new NonStrictExpectations() {{
Request request = new Request(HttpMethod.GET,
Domains.LOOKUPS.toString(),
"/v1/PhoneNumbers/+15017122661");
"/v1/PhoneNumbers/%2B15017122661");

twilioRestClient.request(request);
times = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testFetchRequest() {
new NonStrictExpectations() {{
Request request = new Request(HttpMethod.GET,
Domains.PRICING.toString(),
"/v1/Voice/Numbers/+15017122661");
"/v1/Voice/Numbers/%2B15017122661");

twilioRestClient.request(request);
times = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testFetchRequest() {
new NonStrictExpectations() {{
Request request = new Request(HttpMethod.GET,
Domains.PRICING.toString(),
"/v2/Voice/Numbers/+15017122661");
"/v2/Voice/Numbers/%2B15017122661");

twilioRestClient.request(request);
times = 1;
Expand Down