Skip to content

Commit 2411844

Browse files
committed
Merge branch 'develop' into feature/site-settings-review
Conflicts: WordPress/src/main/res/values/strings.xml
2 parents 53c3a16 + 43eac0e commit 2411844

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

WordPressUtils/src/androidTest/java/org/wordpress/android/util/UrlUtilsTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,18 @@ public void testAppendUrlParameters1() {
6161
params.put("w", "200");
6262
params.put("h", "300");
6363
String url = UrlUtils.appendUrlParameters("http://wp.com/test", params);
64-
assertEquals("http://wp.com/test?h=300&w=200", url);
64+
if (!url.equals("http://wp.com/test?h=300&w=200") && !url.equals("http://wp.com/test?w=200&h=300")) {
65+
assertTrue("failed test on url: " + url, false);
66+
}
6567
}
6668

6769
public void testAppendUrlParameters2() {
6870
Map<String, String> params = new HashMap<>();
6971
params.put("h", "300");
7072
params.put("w", "200");
7173
String url = UrlUtils.appendUrlParameters("/relative/test", params);
72-
assertEquals("/relative/test?h=300&w=200", url);
74+
if (!url.equals("/relative/test?h=300&w=200") && !url.equals("/relative/test?w=200&h=300")) {
75+
assertTrue("failed test on url: " + url, false);
76+
}
7377
}
7478
}

WordPressUtils/src/main/java/org/wordpress/android/util/BlogUtils.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ public class BlogUtils {
88
public int compare(Object blog1, Object blog2) {
99
Map<String, Object> blogMap1 = (Map<String, Object>) blog1;
1010
Map<String, Object> blogMap2 = (Map<String, Object>) blog2;
11-
String blogName1 = getBlogNameOrHostNameFromAccountMap(blogMap1);
12-
String blogName2 = getBlogNameOrHostNameFromAccountMap(blogMap2);
11+
String blogName1 = getBlogNameOrHomeURLFromAccountMap(blogMap1);
12+
String blogName2 = getBlogNameOrHomeURLFromAccountMap(blogMap2);
1313
return blogName1.compareToIgnoreCase(blogName2);
1414
}
1515
};
1616

1717
/**
18-
* Return a blog name or blog url (host part only) if trimmed name is an empty string
18+
* Return a blog name or blog home URL if trimmed name is an empty string
1919
*/
20-
public static String getBlogNameOrHostNameFromAccountMap(Map<String, Object> account) {
20+
public static String getBlogNameOrHomeURLFromAccountMap(Map<String, Object> account) {
2121
String blogName = getBlogNameFromAccountMap(account);
2222
if (blogName.trim().length() == 0) {
23-
blogName = StringUtils.getHost(MapUtils.getMapStr(account, "url"));
23+
blogName = BlogUtils.getHomeURLOrHostNameFromAccountMap(account);
2424
}
2525
return blogName;
2626
}
@@ -33,9 +33,16 @@ public static String getBlogNameFromAccountMap(Map<String, Object> account) {
3333
}
3434

3535
/**
36-
* Return blog url (host part only) if trimmed name is an empty string
36+
* Return the blog home URL setting or the host name if home URL is an empty string.
3737
*/
38-
public static String getHostNameFromAccountMap(Map<String, Object> account) {
39-
return StringUtils.getHost(MapUtils.getMapStr(account, "url"));
38+
public static String getHomeURLOrHostNameFromAccountMap(Map<String, Object> account) {
39+
String homeURL = UrlUtils.removeScheme(MapUtils.getMapStr(account, "homeURL"));
40+
homeURL = StringUtils.removeTrailingSlash(homeURL);
41+
42+
if (homeURL.length() == 0) {
43+
return StringUtils.getHost(MapUtils.getMapStr(account, "url"));
44+
}
45+
46+
return homeURL;
4047
}
4148
}

WordPressUtils/src/main/java/org/wordpress/android/util/StringUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ public static String capitalize(final String str) {
181181
return new StringBuilder(strLen).append(Character.toTitleCase(firstChar)).append(str.substring(1)).toString();
182182
}
183183

184+
public static String removeTrailingSlash(final String str) {
185+
if (TextUtils.isEmpty(str) || !str.endsWith("/")) {
186+
return str;
187+
}
188+
189+
return str.substring(0, str.length() -1);
190+
}
191+
184192
/*
185193
* Wrap an image URL in a photon URL
186194
* Check out http://developer.wordpress.com/docs/photon/

WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,25 @@ public static String normalizeUrl(final String urlString) {
138138
}
139139
}
140140

141+
142+
/**
143+
* returns the passed url without the scheme
144+
*/
145+
public static String removeScheme(final String urlString) {
146+
if (urlString == null) {
147+
return null;
148+
}
149+
150+
int doubleslash = urlString.indexOf("//");
151+
if (doubleslash == -1) {
152+
doubleslash = 0;
153+
} else {
154+
doubleslash += 2;
155+
}
156+
157+
return urlString.substring(doubleslash, urlString.length());
158+
}
159+
141160
/**
142161
* returns the passed url without the query parameters
143162
*/

0 commit comments

Comments
 (0)