Skip to content
Browse files

TFJ-735 Fixed profile urls without extensions parsing

  • Loading branch information...
1 parent 1a87b36 commit aa6e62fb6c5ca1114703e133cd2bff6c6ccd92a9 @DHuckaby DHuckaby committed with DHuckaby Dec 10, 2012
View
11 twitter4j-core/src/main/java/twitter4j/internal/json/UserJSONImpl.java
@@ -245,12 +245,15 @@ public String getOriginalProfileImageURL() {
}
private String toResizedURL(String originalURL, String sizeSuffix) {
- if(null != originalURL){
+ if (null != originalURL) {
int index = originalURL.lastIndexOf("_");
int suffixIndex = originalURL.lastIndexOf(".");
- return originalURL.substring(0,index)
- +sizeSuffix
- +originalURL.substring(suffixIndex);
+ int slashIndex = originalURL.lastIndexOf("/");
+ String url = originalURL.substring(0, index) + sizeSuffix;
+ if (suffixIndex > slashIndex) {
+ url += originalURL.substring(suffixIndex);
+ }
+ return url;
}
return null;
}
View
17 twitter4j-core/src/test/java/twitter4j/internal/json/UserJSONImplTest.java
@@ -63,5 +63,20 @@ public void testGetDescriptionURLEntities2() throws JSONException, TwitterExcept
assertEquals(null, userWithoutDescription.getDescription());
assertEquals(0, userWithoutDescription.getDescriptionURLEntities().length);
}
-
+
+ public void testProfileImageURL() throws JSONException, TwitterException {
+ String rawJsonWithoutProfileImageExtension = "{\"id\":400609977,\"id_str\":\"400609977\",\"name\":\"Chris Bautista\",\"screen_name\":\"ayecrispy\",\"location\":\"Jacksonville, FL\",\"description\":\"I'm a gamer and will always be one. I like to keep up with the entertainment life. Where it's celebrities, technology or trying to keep up with latest trend\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":17,\"friends_count\":177,\"listed_count\":0,\"created_at\":\"Sat Oct 29 09:23:10 +0000 2011\",\"favourites_count\":0,\"utc_offset\":-18000,\"time_zone\":\"Eastern Time (US & Canada)\",\"geo_enabled\":false,\"verified\":false,\"statuses_count\":113,\"lang\":\"en\",\"status\":{\"created_at\":\"Sun Dec 16 02:37:57 +0000 2012\",\"id\":280139673333035008,\"id_str\":\"280139673333035008\",\"text\":\"Gotta love olive Garden!\",\"source\":\"\\u003ca href=\\\"http:\\/\\/tweedleapp.com\\/\\\" rel=\\\"nofollow\\\"\\u003e Tweedle\\u003c\\/a\\u003e\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"entities\":{\"hashtags\":[],\"urls\":[],\"user_mentions\":[]},\"favorited\":false,\"retweeted\":false},\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"1A1B1F\",\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/images\\/themes\\/theme9\\/bg.gif\",\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/images\\/themes\\/theme9\\/bg.gif\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1835646533\\/gu44kEhi_normal\",\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1835646533\\/gu44kEhi_normal\",\"profile_link_color\":\"2FC2EF\",\"profile_sidebar_border_color\":\"181A1E\",\"profile_sidebar_fill_color\":\"252429\",\"profile_text_color\":\"666666\",\"profile_use_background_image\":true,\"default_profile\":false,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false}";
+ JSONObject jsonWithoutProfileImageExtension = new JSONObject(rawJsonWithoutProfileImageExtension);
+ UserJSONImpl userWithoutProfileImageExtension = new UserJSONImpl(jsonWithoutProfileImageExtension);
+
+ assertEquals(userWithoutProfileImageExtension.getBiggerProfileImageURL(), "http://si0.twimg.com/profile_images/1835646533/gu44kEhi_bigger");
+ assertEquals(userWithoutProfileImageExtension.getOriginalProfileImageURL(), "http://si0.twimg.com/profile_images/1835646533/gu44kEhi");
+
+ String rawJsonWithProfileImageExtension = "{\"id\":613742117,\"id_str\":\"613742117\",\"name\":\"Tweedle\",\"screen_name\":\"tweedleapp\",\"location\":\"\",\"description\":\"Twitter application for Android, follow this account for updates.\\r\\n\\r\\nDeveloped by @HandlerExploit\",\"url\":\"http:\\/\\/tweedleapp.com\",\"entities\":{\"url\":{\"urls\":[{\"url\":\"http:\\/\\/tweedleapp.com\",\"expanded_url\":null,\"indices\":[0,21]}]},\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":2210,\"friends_count\":1,\"listed_count\":20,\"created_at\":\"Wed Jun 20 20:42:48 +0000 2012\",\"favourites_count\":1,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":false,\"verified\":false,\"statuses_count\":323,\"lang\":\"en\",\"status\":{\"created_at\":\"Sun Dec 16 06:47:33 +0000 2012\",\"id\":280202487317790721,\"id_str\":\"280202487317790721\",\"text\":\"@bcw_ It is better in some aspects, but in others it is not ideal. We need to add a way to notify the user better though.\",\"source\":\"web\",\"truncated\":false,\"in_reply_to_status_id\":280202314080464896,\"in_reply_to_status_id_str\":\"280202314080464896\",\"in_reply_to_user_id\":101066646,\"in_reply_to_user_id_str\":\"101066646\",\"in_reply_to_screen_name\":\"bcw_\",\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"entities\":{\"hashtags\":[],\"urls\":[],\"user_mentions\":[{\"screen_name\":\"bcw_\",\"name\":\"Verified Bradley\",\"id\":101066646,\"id_str\":\"101066646\",\"indices\":[0,5]}]},\"favorited\":false,\"retweeted\":false},\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/2433552309\\/dltv4u9hajvoxsne5bly_normal.png\",\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/2433552309\\/dltv4u9hajvoxsne5bly_normal.png\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":true,\"follow_request_sent\":false,\"notifications\":false}";
+ JSONObject jsonWithProfileImageExtension = new JSONObject(rawJsonWithProfileImageExtension);
+ UserJSONImpl userWithProfileImageExtension = new UserJSONImpl(jsonWithProfileImageExtension);
+
+ assertEquals(userWithProfileImageExtension.getBiggerProfileImageURL(), "http://si0.twimg.com/profile_images/2433552309/dltv4u9hajvoxsne5bly_bigger.png");
+ assertEquals(userWithProfileImageExtension.getOriginalProfileImageURL(), "http://si0.twimg.com/profile_images/2433552309/dltv4u9hajvoxsne5bly.png");
+ }
}

0 comments on commit aa6e62f

Please sign in to comment.
Something went wrong with that request. Please try again.