Skip to content

Commit

Permalink
close #430 Ensure any specified filename is shortened to the maximum …
Browse files Browse the repository at this point in the history
…length supported by the OS
  • Loading branch information
ediweissmann committed Mar 9, 2024
1 parent 8b3a1d6 commit a331e8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public String getSpecificResultFilename(int fileNumber, String expectedExtension
}
return n;
})
.map(IOUtils::shortenFilename)
.orElse(null);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.sejda.impl.sambox;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.sejda.model.optimization.OptimizationPolicy;
Expand Down Expand Up @@ -238,6 +239,24 @@ public void specificResultFilenames_invalidCharacters() throws IOException {
testContext.assertOutputContainsFilenames("pathtosomewhere.pdf", "`&aaa.pdf", "3_medium-test-file.pdf");
}

@Test
public void specificResultFilenames_tooLong() throws IOException {
setUpParameters();
parameters.addSource(mediumInput());
parameters.addPage(1);
parameters.addPage(2);

String longfilename = StringUtils.repeat("abcde012345", 200) + ".pdf";
parameters.addSpecificResultFilename(longfilename);

execute(parameters);

testContext.assertTaskCompleted();
testContext.assertOutputSize(3);
testContext.assertOutputContainsFilenames("abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde012345abcde0123.pdf",
"2_medium-test-file.pdf", "3_medium-test-file.pdf");
}

@Test
public void sharedResourcesAreNotPurged() throws IOException {
setUpParameters();
Expand Down

0 comments on commit a331e8b

Please sign in to comment.