From f5e169249fd67c91866796bebee6a0ade31b518b Mon Sep 17 00:00:00 2001 From: seven332 Date: Thu, 4 Jul 2019 22:05:18 +0800 Subject: [PATCH] Fix picture url --- .../hippo/nimingban/client/data/ACSite.java | 3 +- .../main/java/com/hippo/util/UrlUtils.java | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/hippo/util/UrlUtils.java diff --git a/app/src/main/java/com/hippo/nimingban/client/data/ACSite.java b/app/src/main/java/com/hippo/nimingban/client/data/ACSite.java index 2f191dea..6d3067d5 100644 --- a/app/src/main/java/com/hippo/nimingban/client/data/ACSite.java +++ b/app/src/main/java/com/hippo/nimingban/client/data/ACSite.java @@ -24,6 +24,7 @@ import com.hippo.nimingban.network.HttpCookieWithId; import com.hippo.nimingban.network.SimpleCookieStore; import com.hippo.nimingban.util.Settings; +import com.hippo.util.UrlUtils; import com.hippo.yorozuya.MathUtils; import java.net.HttpCookie; import java.net.MalformedURLException; @@ -191,7 +192,7 @@ public synchronized String getPictureUrl(String key) { ACCdnPath cdnPath; if (mCdnPathList != null && (cdnPath = getCdnPath()) != null) { - url = cdnPath.url + key; + url = UrlUtils.join(cdnPath.url, key); } else { url = DEFAULT_PICTURE_PREFIX + key; } diff --git a/app/src/main/java/com/hippo/util/UrlUtils.java b/app/src/main/java/com/hippo/util/UrlUtils.java new file mode 100644 index 00000000..e2f6e79f --- /dev/null +++ b/app/src/main/java/com/hippo/util/UrlUtils.java @@ -0,0 +1,35 @@ +/* + * Copyright 2019 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.util; + +import android.support.annotation.NonNull; + +public class UrlUtils { + + public static String join(@NonNull String s1, @NonNull String s2) { + boolean endsWith = s1.endsWith("/"); + boolean startsWith = s2.startsWith("/"); + + if (endsWith ^ startsWith) { + return s1 + s2; + } else if (endsWith) { + return s1 + s2.substring(1); + } else { + return s1 + "/" + s2; + } + } +}