From 856c03f13a63f3757edcce4e60f3b0b5d90b61f4 Mon Sep 17 00:00:00 2001
From: Etienne Lamoureux <3357406+EtienneLamoureux@users.noreply.github.com>
Date: Sun, 18 Jul 2021 19:39:37 -0400
Subject: [PATCH] Fix URL concatenation Fix
https://github.com/Patreon/patreon-java/issues/40
---
CHANGELOG.md | 4 ++++
pom.xml | 2 +-
.../java/com/patreon/resources/RequestUtil.java | 14 ++++++++++++--
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dbde2f0..5dee835 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 0.4.3
+## Fixed
+* URL concatenation on the different versions of the JDK and upstream projects' dependencies
+
# 0.4.2
## Fixed
* GRANT_TYPE_TOKEN_REFRESH now has the correct value
diff --git a/pom.xml b/pom.xml
index ad4df3c..0a4a129 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,7 +78,7 @@ and https://issues.apache.org/jira/browse/SUREFIRE-1588 -->
com.patreon
patreon
- 0.4.2
+ 0.4.3
${project.groupId}:${project.artifactId}
Interact with the Patreon API via OAuth
diff --git a/src/main/java/com/patreon/resources/RequestUtil.java b/src/main/java/com/patreon/resources/RequestUtil.java
index cabb20e..9ed0820 100644
--- a/src/main/java/com/patreon/resources/RequestUtil.java
+++ b/src/main/java/com/patreon/resources/RequestUtil.java
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
import java.net.URL;
import static com.patreon.PatreonAPI.BASE_URI;
@@ -13,8 +14,7 @@
public class RequestUtil {
public InputStream request(String pathSuffix, String accessToken) throws IOException {
- String prefix = BASE_URI + "/api/oauth2/api/";
- URL url = new URL(prefix.concat(pathSuffix));
+ URL url = buildUrl(pathSuffix);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization", "Bearer ".concat(accessToken));
connection.setRequestProperty("User-Agent",
@@ -26,6 +26,16 @@ public InputStream request(String pathSuffix, String accessToken) throws IOExcep
return connection.getInputStream();
}
+ private URL buildUrl(String pathSuffix) throws MalformedURLException {
+ if (pathSuffix.startsWith("/")) {
+ pathSuffix = pathSuffix.substring(1, pathSuffix.length());
+ }
+
+ String prefix = BASE_URI + "/api/oauth2/api/";
+ URL url = new URL(prefix.concat(pathSuffix));
+ return url;
+ }
+
private String getVersion() throws IOException {
InputStream resourceAsStream = this.getClass().getResourceAsStream("/version.properties");
java.util.Properties prop = new java.util.Properties();