Skip to content

Commit c7ec2ac

Browse files
ZCU-PUB/The bitstream name is encoded in the URL. Updated the test to test special characters in the URL (#930)
1 parent 1ce5eac commit c7ec2ac

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

dspace-server-webapp/src/test/java/org/dspace/app/sword2/Swordv2IT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ public void depositAndEditViaSwordTest() throws Exception {
258258
// Add required headers
259259
HttpHeaders headers = new HttpHeaders();
260260
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
261-
headers.setContentDisposition(ContentDisposition.attachment().filename("example.zip").build());
261+
// Test the file with spaces or special characters in the name
262+
headers.setContentDisposition(ContentDisposition.attachment().filename("example .zip").build());
262263
headers.set("Packaging", "http://purl.org/net/sword/package/METSDSpaceSIP");
263264
headers.setAccept(List.of(MediaType.APPLICATION_ATOM_XML));
264265

dspace-swordv2/src/main/java/org/dspace/sword2/SwordUrlManager.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
package org.dspace.sword2;
99

10+
import java.net.URLEncoder;
11+
import java.nio.charset.StandardCharsets;
1012
import java.sql.SQLException;
1113
import java.util.List;
1214

@@ -386,10 +388,10 @@ public String getBitstreamUrl(Bitstream bitstream)
386388

387389
if (handle != null && !"".equals(handle)) {
388390
bsLink = bsLink + "/bitstream/" + handle + "/" +
389-
bitstream.getSequenceID() + "/" + bitstream.getName();
391+
bitstream.getSequenceID() + "/" + URLEncoder.encode(bitstream.getName(), StandardCharsets.UTF_8);
390392
} else {
391393
bsLink = bsLink + "/retrieve/" + bitstream.getID() + "/" +
392-
bitstream.getName();
394+
URLEncoder.encode(bitstream.getName(), StandardCharsets.UTF_8);
393395
}
394396

395397
return bsLink;
@@ -401,7 +403,7 @@ public String getBitstreamUrl(Bitstream bitstream)
401403
public String getActionableBitstreamUrl(Bitstream bitstream)
402404
throws DSpaceSwordException {
403405
return this.getSwordBaseUrl() + "/edit-media/bitstream/" +
404-
bitstream.getID() + "/" + bitstream.getName();
406+
bitstream.getID() + "/" + URLEncoder.encode(bitstream.getName(), StandardCharsets.UTF_8);
405407
}
406408

407409
public boolean isActionableBitstreamUrl(Context context, String url) {

0 commit comments

Comments
 (0)