diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c97f005429c..fd89977e7974 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve ### Fixed +- We fixed an issue where converting empty fields led to an exception [#9200](https://github.com/JabRef/jabref/issues/9200) - We fixed an issue where author names with tilde accents (for example ñ) were marked as "Names are not in the standard BibTex format" [#8071](https://github.com/JabRef/jabref/issues/8071) - We fixed an issue where the possibility to generate a subdatabase from an aux file was writing empty files when called from the commandline [#9115](https://github.com/JabRef/jabref/issues/9115), [forum#3516](https://discourse.jabref.org/t/export-subdatabase-from-aux-file-on-macos-command-line/3516) - We fixed the display of issue, number, eid and pages fields in the entry preview. [#8607](https://github.com/JabRef/jabref/pull/8607), [#8372](https://github.com/JabRef/jabref/issues/8372), [Koppor#514](https://github.com/koppor/jabref/issues/514), [forum#2390](https://discourse.jabref.org/t/unable-to-edit-my-bibtex-file-that-i-used-before-vers-5-1/2390), [forum#3462](https://discourse.jabref.org/t/jabref-5-6-need-help-with-export-from-jabref-to-microsoft-word-entry-preview-of-apa-7-not-rendering-correctly/3462) diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java index 336649834254..c340455538cd 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatter.java @@ -26,7 +26,7 @@ public class HtmlToLatexFormatter extends Formatter implements LayoutFormatter { @Override public String format(String text) { - String result = Objects.requireNonNull(text); + String result = Objects.requireNonNullElse(text, ""); if (result.isEmpty()) { return result; diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatter.java index 5ff4e95bb71a..eb2b58ebc708 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatter.java @@ -7,6 +7,8 @@ import org.apache.commons.lang3.StringEscapeUtils; +import java.util.Objects; + @ApacheCommonsLang3Allowed("There is no equivalent in Google's Guava") public class HtmlToUnicodeFormatter extends Formatter implements LayoutFormatter { @@ -33,6 +35,7 @@ public String getExampleInput() { @Override public String format(String fieldText) { // StringEscapeUtils converts characters and regex kills tags - return StringEscapeUtils.unescapeHtml4(fieldText).replaceAll("<[^>]*>", ""); + String result = Objects.requireNonNullElse(fieldText, ""); + return StringEscapeUtils.unescapeHtml4(result).replaceAll("<[^>]*>", ""); } } diff --git a/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java b/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java index ee7a663da76f..913afd23b45e 100644 --- a/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java +++ b/src/main/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatter.java @@ -17,8 +17,7 @@ public class UnicodeToLatexFormatter extends Formatter implements LayoutFormatte @Override public String format(String text) { - String result = Objects.requireNonNull(text); - + String result = Objects.requireNonNullElse(text, ""); if (result.isEmpty()) { return result; } diff --git a/src/main/java/org/jabref/model/strings/LatexToUnicodeAdapter.java b/src/main/java/org/jabref/model/strings/LatexToUnicodeAdapter.java index 01c4c304ef29..ff7e44a4744f 100644 --- a/src/main/java/org/jabref/model/strings/LatexToUnicodeAdapter.java +++ b/src/main/java/org/jabref/model/strings/LatexToUnicodeAdapter.java @@ -26,8 +26,8 @@ public class LatexToUnicodeAdapter { * @return a String with LaTeX resolved into Unicode, or the original String if the LaTeX could not be parsed */ public static String format(String inField) { - Objects.requireNonNull(inField); - return parse(inField).orElse(Normalizer.normalize(inField, Normalizer.Form.NFC)); + String result = Objects.requireNonNullElse(inField, ""); + return parse(result).orElse(Normalizer.normalize(result, Normalizer.Form.NFC)); } /** diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java index 3ecd073a9173..84ee888d58c5 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java @@ -39,6 +39,8 @@ public void testBasic() { @Test public void testHTML() { + assertEquals("", formatter.format(null)); + assertEquals("", formatter.format("")); assertEquals("{\\\"{a}}", formatter.format("ä")); assertEquals("{\\\"{a}}", formatter.format("ä")); assertEquals("{\\\"{a}}", formatter.format("ä")); diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java index 64f14737bb9a..db54baf06bfe 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java @@ -15,6 +15,8 @@ public class HtmlToUnicodeFormatterTest { private static Stream data() { return Stream.of( + Arguments.of("", ""), + Arguments.of("", null), Arguments.of("abc", "abc"), Arguments.of("åäö", "åäö"), Arguments.of("í", "í"), diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java index 2f43db8a4fef..5be375ce2ad6 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java @@ -20,6 +20,7 @@ void setUp() { private static Stream testCases() { return Stream.of( + Arguments.of("", null), // empty string input Arguments.of("", ""), // empty string input Arguments.of("abc", "abc"), // non unicode input Arguments.of("{{\\aa}}{\\\"{a}}{\\\"{o}}", "\u00E5\u00E4\u00F6"), // multiple unicodes input diff --git a/src/test/java/org/jabref/logic/layout/format/LatexToUnicodeFormatterTest.java b/src/test/java/org/jabref/logic/layout/format/LatexToUnicodeFormatterTest.java index f48963ff923b..b6e48f736954 100644 --- a/src/test/java/org/jabref/logic/layout/format/LatexToUnicodeFormatterTest.java +++ b/src/test/java/org/jabref/logic/layout/format/LatexToUnicodeFormatterTest.java @@ -110,6 +110,11 @@ void keepUnknownCommandWithoutArgument() { assertEquals("\\aaaa", formatter.format("\\aaaa")); } + @Test + void keepUnknownCommandWithNullArgument() { + assertEquals("", formatter.format(null)); + } + @Test void keepUnknownCommandWithArgument() { assertEquals("\\aaaa{bbbb}", formatter.format("\\aaaa{bbbb}"));