Skip to content

Commit b482496

Browse files
committed
fix
1 parent 5f97e6a commit b482496

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

src/main/java/com/qiniu/api/net/EncodeUtils.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ public static byte[] urlsafeEncodeBytes(byte[] src) {
3838
}
3939

4040
public static byte[] urlsafeBase64Decode(String encoded){
41-
byte[] db64 = Base64.decodeBase64(encoded);
42-
for(int i=0;i<db64.length;i++){
43-
if(db64[i] == '_'){
44-
db64[i] = '/';
45-
}else if(db64[i] == '-'){
46-
db64[i] = '+';
41+
byte[] rawbs = encoded.getBytes();
42+
for(int i=0;i<rawbs.length;i++){
43+
if(rawbs[i] == '_'){
44+
rawbs[i] = '/';
45+
}else if(rawbs[i] == '-'){
46+
rawbs[i] = '+';
4747
}
4848
}
49+
byte[] db64 = Base64.decodeBase64(rawbs);
4950
return db64;
5051
}
5152

src/main/java/com/qiniu/api/rs/PutPolicy.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class PutPolicy {
3232
public String endUser;
3333
/** 可选 */
3434
public long expires;
35+
36+
public long deadline;
3537

3638
public PutPolicy(String scope) {
3739
this.scope = scope;
@@ -59,7 +61,7 @@ private String marshal() throws JSONException {
5961
if (this.endUser != null && this.endUser.length() > 0) {
6062
stringer.key("endUser").value(this.endUser);
6163
}
62-
stringer.key("deadline").value(this.expires);
64+
stringer.key("deadline").value(this.deadline);
6365
stringer.endObject();
6466

6567
return stringer.toString();
@@ -78,10 +80,8 @@ public String token(Mac mac) throws AuthException, JSONException {
7880
if (this.expires == 0) {
7981
this.expires = 3600; // 3600s, default.
8082
}
81-
long orign = this.expires;
82-
this.expires = System.currentTimeMillis() / 1000 + expires;
83+
this.deadline = System.currentTimeMillis() / 1000 + this.expires;
8384
byte[] data = this.marshal().getBytes();
84-
this.expires = orign;
8585
return DigestAuth.signWithData(mac, data);
8686
}
8787

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.qiniu.testing;
2+
3+
4+
import junit.framework.TestCase;
5+
6+
import com.qiniu.api.net.EncodeUtils;
7+
8+
public class UtilTest extends TestCase {
9+
10+
// just upload an image in testdata.
11+
public void test() throws Exception {
12+
String expectString = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+}{:?><-=,./;'[]";
13+
String encodedString = "MTIzNDU2Nzg5MGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVp-IUAjJCVeJiooKV8rfXs6Pz48LT0sLi87J1td";
14+
byte[] rawBytes = EncodeUtils.urlsafeBase64Decode(encodedString);
15+
String decoded = new String(rawBytes);
16+
assertTrue(expectString.equals(decoded));
17+
}
18+
19+
@Override
20+
public void tearDown() {
21+
// do nothing here.
22+
}
23+
}

0 commit comments

Comments
 (0)