Skip to content

Commit af84bbe

Browse files
liyanzhang505huiguangjun
authored andcommitted
Fix deleteVersions key escape issue
1 parent 5bb135c commit af84bbe

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ public byte[] marshall(DeleteVersionsRequest request) {
700700
KeyVersion key = keysToDelete.get(i);
701701
xmlBody.append("<Object>");
702702
xmlBody.append("<Key>" +
703-
escapeKey(HttpUtil.urlEncode(key.getKey(), StringUtils.DEFAULT_ENCODING)) + "</Key>");
703+
escapeKey(key.getKey()) + "</Key>");
704704
if (key.getVersion() != null) {
705705
xmlBody.append("<VersionId>" + key.getVersion() + "</VersionId>");
706706
}

src/main/java/com/aliyun/oss/model/ListVersionsRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public class ListVersionsRequest extends GenericRequest {
151151
* can add this parameter to request that OSS encode the keys in the
152152
* response.
153153
*/
154-
private String encodingType = OSSConstants.URL_ENCODING;
154+
private String encodingType;
155155

156156

157157
/**

src/test/java/com/aliyun/oss/integrationtests/ListVersionsTest.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,15 @@
3333
import com.aliyun.oss.common.auth.Credentials;
3434
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
3535
import com.aliyun.oss.common.auth.DefaultCredentials;
36+
import com.aliyun.oss.internal.OSSConstants;
37+
import com.aliyun.oss.model.*;
3638
import junit.framework.Assert;
3739

3840
import org.junit.Test;
3941

4042
import com.aliyun.oss.OSSErrorCode;
4143
import com.aliyun.oss.OSSException;
42-
import com.aliyun.oss.model.ListVersionsRequest;
43-
import com.aliyun.oss.model.OSSVersionSummary;
44-
import com.aliyun.oss.model.VersionListing;
45-
import com.aliyun.oss.model.BucketVersioningConfiguration;
46-
import com.aliyun.oss.model.SetBucketVersioningRequest;
44+
import com.aliyun.oss.model.DeleteVersionsRequest.KeyVersion;
4745

4846
public class ListVersionsTest extends TestBase {
4947

@@ -176,8 +174,7 @@ public void testListVersionsWithEncodingType() {
176174
// Unormal
177175
ListVersionsRequest listVersionsRequest = new ListVersionsRequest()
178176
.withBucketName(bucketName)
179-
.withPrefix(objectPrefix)
180-
.withEncodingType(null);
177+
.withPrefix(objectPrefix);
181178

182179
ossClient.listVersions(listVersionsRequest);
183180
Assert.fail("List version should not be successful.");
@@ -189,12 +186,19 @@ public void testListVersionsWithEncodingType() {
189186
// Normal
190187
ListVersionsRequest listVersionsRequest = new ListVersionsRequest()
191188
.withBucketName(bucketName)
192-
.withPrefix(objectPrefix);
189+
.withPrefix(objectPrefix)
190+
.withEncodingType(OSSConstants.URL_ENCODING);
193191

194192
VersionListing versionListing = ossClient.listVersions(listVersionsRequest);
195-
for (OSSVersionSummary version : versionListing.getVersionSummaries()) {
196-
String decodedKey = URLDecoder.decode(version.getKey(), "UTF-8");
197-
Assert.assertTrue(existingKeys.contains(decodedKey));
193+
if (versionListing.getVersionSummaries().size() > 0) {
194+
List<KeyVersion> keyVersionsList = new ArrayList<KeyVersion>();
195+
for (OSSVersionSummary version : versionListing.getVersionSummaries()) {
196+
String decodedKey = URLDecoder.decode(version.getKey(), "UTF-8");
197+
Assert.assertTrue(existingKeys.contains(decodedKey));
198+
keyVersionsList.add(new KeyVersion(version.getKey(), version.getVersionId()));
199+
}
200+
DeleteVersionsRequest delVersionsRequest = new DeleteVersionsRequest(bucketName).withKeys(keyVersionsList);
201+
ossClient.deleteVersions(delVersionsRequest);
198202
}
199203
Assert.assertNull(versionListing.getEncodingType());
200204
} catch (Exception e) {

src/test/java/com/aliyun/oss/integrationtests/ObjectVersionTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.aliyun.oss.common.auth.Credentials;
3232
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
3333
import com.aliyun.oss.common.auth.DefaultCredentials;
34+
import com.aliyun.oss.internal.OSSUtils;
3435
import junit.framework.Assert;
3536

3637
import org.junit.Test;
@@ -70,6 +71,7 @@
7071
import com.aliyun.oss.model.SetBucketVersioningRequest;
7172

7273
import static com.aliyun.oss.integrationtests.TestUtils.*;
74+
import static org.junit.Assert.assertTrue;
7375

7476
public class ObjectVersionTest extends TestBase {
7577

@@ -222,8 +224,8 @@ public void tesDeleteVersion() {
222224
}
223225

224226
@Test
225-
public void tesDeleteVersions() {
226-
String prefix = "version-test-del-multiple-versions";
227+
public void testDeleteVersions() {
228+
String prefix = (char)9 + "" + (char)0x20 + "123_.* 中文-!@#$%^&*()_+-=;'\"~`><?/':[]|\\";
227229
long inputStreamLength = 1024;
228230
String key = null;
229231

0 commit comments

Comments
 (0)