Skip to content

Commit

Permalink
quote Pattern for thumbnail resolution constructed from bitstream fil…
Browse files Browse the repository at this point in the history
…ename
  • Loading branch information
floriangantner committed Oct 10, 2023
1 parent 92844f0 commit a124807
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public Bitstream getFirstBitstream(Item item, String bundleName) throws SQLExcep

@Override
public Bitstream getThumbnail(Context context, Bitstream bitstream) throws SQLException {
Pattern pattern = Pattern.compile("^" + bitstream.getName() + ".([^.]+)$");
Pattern pattern = Pattern.compile("^" + Pattern.quote(bitstream.getName()) + ".([^.]+)$");

for (Bundle bundle : bitstream.getBundles()) {
for (Item item : bundle.getItems()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,53 @@ public void thumbnailEndpointTest() throws Exception {
.andExpect(jsonPath("$.type", is("bitstream")));
}

@Test
public void thumbnailEndpointTestWithSpecialCharactersInFileName() throws Exception {
// Given an Item
context.turnOffAuthorisationSystem();

parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();

Collection col1 = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection 1").build();

Item item = ItemBuilder.createItem(context, col1)
.withTitle("Test item -- thumbnail")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.build();

Bundle originalBundle = BundleBuilder.createBundle(context, item)
.withName(Constants.DEFAULT_BUNDLE_NAME)
.build();
Bundle thumbnailBundle = BundleBuilder.createBundle(context, item)
.withName("THUMBNAIL")
.build();

InputStream is = IOUtils.toInputStream("dummy", "utf-8");

// With an ORIGINAL Bitstream & matching THUMBNAIL Bitstream containing special characters in filenames
Bitstream bitstream = BitstreamBuilder.createBitstream(context, originalBundle, is)
.withName("test (2023) file.pdf")
.withMimeType("application/pdf")
.build();
Bitstream thumbnail = BitstreamBuilder.createBitstream(context, thumbnailBundle, is)
.withName("test (2023) file.pdf.jpg")
.withMimeType("image/jpeg")
.build();

context.restoreAuthSystemState();

String tokenAdmin = getAuthToken(admin.getEmail(), password);

getClient(tokenAdmin).perform(get("/api/core/bitstreams/" + bitstream.getID() + "/thumbnail"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.uuid", Matchers.is(thumbnail.getID().toString())))
.andExpect(jsonPath("$.type", is("bitstream")));
}

@Test
public void thumbnailEndpointMultipleThumbnailsWithPrimaryBitstreamTest() throws Exception {
// Given an Item
Expand Down

0 comments on commit a124807

Please sign in to comment.