Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where an exception would occur when running abbreviate journals for multiple entries. [#12634](https://github.com/JabRef/jabref/issues/12634)
- We fixed an issue where JabRef displayed dropdown triangle in wrong place in "Search for unlinked local files" dialog [#12713](https://github.com/JabRef/jabref/issues/12713)
- We fixed an issue where JabRef would not open if an invalid external journal abbreviation path was encountered. [#12776](https://github.com/JabRef/jabref/issues/12776)
- We fixed a bug where LaTeX commands were not removed from filenames generated using the `[bibtexkey] - [fulltitle]` pattern. [#12188](https://github.com/JabRef/jabref/issues/12188)

### Removed

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/logic/util/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.jabref.logic.FilePreferences;
import org.jabref.logic.citationkeypattern.BracketedPattern;
import org.jabref.logic.layout.format.RemoveLatexCommandsFormatter;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
Expand Down Expand Up @@ -329,9 +330,12 @@ public static String createFileNameFromPattern(BibDatabase database, BibEntry en
if (targetName.isEmpty()) {
targetName = entry.getCitationKey().orElse("default");
}

// Remove LaTeX commands (e.g., \mkbibquote{}) from expanded fields before cleaning filename
// See: https://github.com/JabRef/jabref/issues/12188
Comment on lines +335 to +336
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment should be in JavaDoc format since it explains the method's behavior. Regular comments should not be used for method documentation according to best practices.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is inside a method, so I kept it as a regular inline one

targetName = new RemoveLatexCommandsFormatter().format(targetName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this a class constant (private static final ...). This saves some time when executing this (we use this pattern in other places in JabRef)

Keep the empty line before.

// Removes illegal characters from filename
targetName = FileNameCleaner.cleanFileName(targetName);

return targetName;
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/jabref/logic/util/io/FileUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ void getLinkedFileNameByYearAuthorFirstpage() {
assertEquals("1868_Kitsune_567", FileUtil.createFileNameFromPattern(null, entry, fileNamePattern));
}

@Test
void getLinkedFileNameRemovesLatexCommands() {
String pattern = "[citationkey] - [fulltitle]";
BibEntry entry = new BibEntry();
entry.setCitationKey("BrayBuildingCommunity");
entry.setField(StandardField.TITLE, "Building \\mkbibquote{Community}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chain - .withCitationKey and .withField.

String expected = "BrayBuildingCommunity - Building Community";
String result = FileUtil.createFileNameFromPattern(null, entry, pattern);
assertEquals(expected, result);
}

@Test
void getFileExtensionSimpleFile() {
assertEquals("pdf", FileUtil.getFileExtension(Path.of("test.pdf")).get());
Expand Down