Skip to content

Commit

Permalink
Fix #5603 - account for file extension in file name length (#5726)
Browse files Browse the repository at this point in the history
* Fix #5603 - account for file extension in file name length

* Update changelog
  • Loading branch information
Ka0o0 authored and tobiasdiez committed Dec 9, 2019
1 parent 8674e70 commit 936eedf
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where the side pane was not remembering its position. [#5615](https://github.com/JabRef/jabref/issues/5615)
- We fixed an issue where JabRef could not interact with [Oracle XE](https://www.oracle.com/de/database/technologies/appdev/xe.html) in the [shared SQL database setup](https://docs.jabref.org/collaborative-work/sqldatabase).
- We fixed an issue where the toolbar icons were hidden on smaller screens.
- We fixed an issue where renaming referenced files for bib entries with long titles was not possible. [#5603](https://github.com/JabRef/jabref/issues/5603)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/util/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static String getValidFileName(String fileName) {

if (nameWithoutExtension.length() > MAXIMUM_FILE_NAME_LENGTH) {
Optional<String> extension = getFileExtension(fileName);
String shortName = nameWithoutExtension.substring(0, MAXIMUM_FILE_NAME_LENGTH);
String shortName = nameWithoutExtension.substring(0, MAXIMUM_FILE_NAME_LENGTH - extension.map(s -> s.length() + 1).orElse(0));
LOGGER.info(String.format("Truncated the too long filename '%s' (%d characters) to '%s'.", fileName, fileName.length(), shortName));
return extension.map(s -> shortName + "." + s).orElse(shortName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jabref/logic/util/io/FileUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void validFilenameWithoutExtension() {

@Test
void validFilenameShouldBeMaximum255Chars() {
String longestValidFilename = Stream.generate(() -> String.valueOf('1')).limit(FileUtil.MAXIMUM_FILE_NAME_LENGTH).collect(Collectors.joining()) + ".pdf";
String longestValidFilename = Stream.generate(() -> String.valueOf('1')).limit(FileUtil.MAXIMUM_FILE_NAME_LENGTH - 4).collect(Collectors.joining()) + ".pdf";
String longerFilename = Stream.generate(() -> String.valueOf('1')).limit(260).collect(Collectors.joining()) + ".pdf";
assertEquals(longestValidFilename, FileUtil.getValidFileName(longerFilename));
}
Expand Down

0 comments on commit 936eedf

Please sign in to comment.