Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
Fix picture url
Browse files Browse the repository at this point in the history
  • Loading branch information
seven332 committed Jul 4, 2019
1 parent f54de53 commit f5e1692
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
35 changes: 35 additions & 0 deletions app/src/main/java/com/hippo/util/UrlUtils.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit f5e1692

Please sign in to comment.