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: paging breaks with + sign on phone number #571

Merged
merged 39 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9277ce2
fix: paging breaks with + sign on phone number
thinkingserious Aug 26, 2020
c4ace54
remove logging
thinkingserious Aug 26, 2020
cd465e7
moved logic to correct function
thinkingserious Aug 27, 2020
d9e02fb
decoder no longer needed
thinkingserious Aug 27, 2020
ef0ca3a
fix test
thinkingserious Aug 27, 2020
616f00b
fix test
thinkingserious Aug 27, 2020
0d000d4
fix test
thinkingserious Aug 27, 2020
0c772f7
revert improper solution
thinkingserious Aug 27, 2020
4d4efb4
do not re-encode
thinkingserious Aug 27, 2020
bb6221e
revert URL builder
thinkingserious Aug 28, 2020
7ed30ad
update test
thinkingserious Aug 28, 2020
f05dc80
avoid double encoding
thinkingserious Aug 28, 2020
b2737af
clean up
thinkingserious Aug 28, 2020
ca5d7c3
add fragment
thinkingserious Aug 28, 2020
5dfaebd
remove logging
thinkingserious Aug 28, 2020
ef6c2d2
Merge branch 'main' into 569-paging-bug
thinkingserious Aug 28, 2020
4511139
build the URL
thinkingserious Sep 1, 2020
6d0e87c
formatting
thinkingserious Sep 1, 2020
be4f84d
Merge branch 'main' into 569-paging-bug
Sep 4, 2020
26c8f6b
Merge branch 'main' of https://github.com/twilio/twilio-java into 569…
thinkingserious Sep 8, 2020
ccc3517
add credentails, user proper encoder
thinkingserious Sep 8, 2020
e5acba8
Merge branch '569-paging-bug' of https://github.com/twilio/twilio-jav…
thinkingserious Sep 8, 2020
1da7850
formatting
thinkingserious Sep 8, 2020
36e9467
formatting
thinkingserious Sep 8, 2020
14e2a31
formatting
thinkingserious Sep 8, 2020
7a77459
Update pom.xml
thinkingserious Sep 8, 2020
92c7ee6
revert to java 7 friendly joiner
thinkingserious Sep 8, 2020
d080a42
fix apache dependency
thinkingserious Sep 8, 2020
8528307
revert to guava joiner
thinkingserious Sep 15, 2020
b0bc241
revert to guava joiner
thinkingserious Sep 15, 2020
380c84c
simplifications
thinkingserious Sep 16, 2020
70770a8
add comment, formatting
thinkingserious Sep 17, 2020
4e25c5d
Merge branch 'main' into 569-paging-bug
thinkingserious Sep 17, 2020
1b03362
remove uncessary param
thinkingserious Sep 17, 2020
1d1e3a0
Merge branch '569-paging-bug' of https://github.com/twilio/twilio-jav…
thinkingserious Sep 17, 2020
908953b
encode all pieces of the path
thinkingserious Sep 17, 2020
aeda0b2
Merge branch 'main' into 569-paging-bug
thinkingserious Sep 17, 2020
958a558
simplification
thinkingserious Sep 17, 2020
f973e48
Merge branch '569-paging-bug' of https://github.com/twilio/twilio-jav…
thinkingserious Sep 17, 2020
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,4 @@
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
</project>
</project>
16 changes: 13 additions & 3 deletions src/main/java/com/twilio/http/Request.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.twilio.http;

import com.google.common.collect.Range;
import com.google.common.base.Joiner;
import com.twilio.exception.ApiException;
import com.twilio.exception.InvalidRequestException;
import org.joda.time.DateTime;
Expand Down Expand Up @@ -175,9 +176,18 @@ private String buildURL() {
host = joinIgnoreNull(".", product, targetEdge, targetRegion, domain);
}

return new URI(parsedUrl.getProtocol(), parsedUrl.getUserInfo(), host, parsedUrl.getPort(),
parsedUrl.getPath(), parsedUrl.getQuery(), parsedUrl.getRef()).toURL().toString();
} catch (final MalformedURLException | URISyntaxException e) {
String urlPort = parsedUrl.getPort() != -1 ? ":" + parsedUrl.getPort() : null;
String protocol = parsedUrl.getProtocol() + "://";
String[] pathPieces = parsedUrl.getPath().split("/");
for (int i = 0; i < pathPieces.length; i++) {
pathPieces[i] = URLEncoder.encode(pathPieces[i], "UTF-8");
}
String encodedPath = Joiner.on("/").join(pathPieces);
String query = parsedUrl.getQuery() != null ? "?" + parsedUrl.getQuery() : null;
String ref = parsedUrl.getRef() != null ? "#" + parsedUrl.getRef() : null;
String credentials = parsedUrl.getUserInfo() != null ? parsedUrl.getUserInfo() + "@" : null;
return joinIgnoreNull("", protocol, credentials, host, urlPort, encodedPath, query, ref);
} catch (final MalformedURLException | UnsupportedEncodingException e) {
throw new ApiException("Bad URL: " + url, e);
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/twilio/http/RequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ public void testConstructURLWithPipe() throws MalformedURLException {
assertUrlsEqual(expected, url);
}

@Test
public void testConstructURLWithMultipleSlashes() throws MalformedURLException {
Request r = new Request(HttpMethod.GET, Domains.API.toString(), "/2010-04-01/foo|bar/bar|foo");
URL url = r.constructURL();
URL expected = new URL("https://api.twilio.com/2010-04-01/foo%7Cbar/bar%7Cfoo");
assertUrlsEqual(expected, url);
}

@Test
public void testConstructURLWithCredentials() throws MalformedURLException {
Request r = new Request(HttpMethod.GET, "user:pass@" + Domains.API.toString(), "/2010-04-01/foobar");
URL url = r.constructURL();
URL expected = new URL("https://user:[email protected]/2010-04-01/foobar");
assertUrlsEqual(expected, url);
}

@Test
public void testConstructURLWithParam() throws MalformedURLException {
Request r = new Request(HttpMethod.GET, Domains.API.toString(), "/2010-04-01/foobar");
Expand All @@ -72,6 +88,15 @@ public void testConstructURLWithParams() throws MalformedURLException {
assertUrlsEqual(expected, url);
}

@Test
public void testConstructURLWithPlusPrefix() {
Request r = new Request(HttpMethod.GET, Domains.API.toString(), "/2010-04-01/foobar");
r.addQueryParam("To", "+18888888888");
URL url = r.constructURL();
String expected = "https://api.twilio.com/2010-04-01/foobar?To=%2B18888888888";
assertEquals(expected, url.toString());
}

@Test
public void testConstructURLWithMultivaluedParam() throws MalformedURLException {
Request r = new Request(HttpMethod.GET, Domains.API.toString(), "/2010-04-01/foobar");
Expand Down