Merge pull request #2109 from nextcloud/bugfix/beautifyEmptyString

Don't beautify empty inputs
This commit is contained in:
Andy Scherzinger 2018-02-12 18:27:51 +01:00 committed by GitHub
commit 2c59093bd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,11 +38,13 @@ import android.graphics.drawable.PictureDrawable;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.Snackbar;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.style.StyleSpan;
import android.view.Menu;
@ -188,20 +190,20 @@ public class DisplayUtils {
* @param url to be beautified url
* @return beautified url
*/
public static String beautifyURL(String url) {
if (url == null) {
public static String beautifyURL(@Nullable String url) {
if (TextUtils.isEmpty(url)) {
return "";
}
if (url.length() >= 7 && url.substring(0, 7).equalsIgnoreCase(HTTP_PROTOCOLL)) {
return url.substring(HTTP_PROTOCOLL.length());
return url.substring(HTTP_PROTOCOLL.length()).trim();
}
if (url.length() >= 8 && url.substring(0, 8).equalsIgnoreCase(HTTPS_PROTOCOLL)) {
return url.substring(HTTPS_PROTOCOLL.length());
return url.substring(HTTPS_PROTOCOLL.length()).trim();
}
return url;
return url.trim();
}
/**
@ -210,15 +212,15 @@ public class DisplayUtils {
* @param handle to be beautified twitter handle
* @return beautified twitter handle
*/
public static String beautifyTwitterHandle(String handle) {
if (handle == null) {
public static String beautifyTwitterHandle(@Nullable String handle) {
if (TextUtils.isEmpty(handle)) {
return "";
}
if (handle.startsWith(TWITTER_HANDLE_PREFIX)) {
return handle;
return handle.trim();
} else {
return TWITTER_HANDLE_PREFIX + handle;
return TWITTER_HANDLE_PREFIX + handle.trim();
}
}