Skip to content

file name & URL validation patch #31

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ target
.gradle
build


#eclipse
.classpath
.project
.settings
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>twitter-api-java-sdk</artifactId>
<packaging>jar</packaging>
<name>twitter-api-java-sdk</name>
<version>2.0.1</version>
<version>2.0.1-nrv</version>
<url>https://github.com/twitterdev/twitter-api-java-sdk</url>
<description>Twitter API v2 available endpoints</description>
<scm>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/twitter/clientlib/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,14 @@ public static void validateJsonObject(JsonObject jsonObj) throws IOException {
if (jsonObj.get("profile_image_url") != null && !jsonObj.get("profile_image_url").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `profile_image_url` to be a primitive type in the JSON string but got `%s`", jsonObj.get("profile_image_url").toString()));
}

// Patch issue #30
if (jsonObj.get("profile_image_url") != null) {
if (jsonObj.get("profile_image_url").getAsString().isBlank()) {
jsonObj.remove("profile_image_url");
}
}

// validate the optional field `public_metrics`
if (jsonObj.getAsJsonObject("public_metrics") != null) {
UserPublicMetrics.validateJsonObject(jsonObj.getAsJsonObject("public_metrics"));
Expand Down