-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix for issue: Sanitization of generated filenames (remove LaTeX commands) #12188 #12802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
57112f2
d3e99a5
7330a1e
7536793
17a2fe3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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 | ||
| targetName = new RemoveLatexCommandsFormatter().format(targetName); | ||
|
||
| // Removes illegal characters from filename | ||
| targetName = FileNameCleaner.cleanFileName(targetName); | ||
|
|
||
| return targetName; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}"); | ||
|
||
| 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()); | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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