From 6da84389ceb906138f6b227ce0bc1146c095ba44 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Wed, 3 Jan 2024 16:50:03 +0100 Subject: [PATCH 1/3] Fix duplicate check not taking umlauts into account Fixes ttps://github.com/JabRef/jabref-issue-melting-pot/issues/249 --- CHANGELOG.md | 1 + .../java/org/jabref/logic/database/DuplicateCheck.java | 10 +++++----- .../org/jabref/logic/database/DuplicateCheckTest.java | 8 ++++++++ .../logic/integrity/ASCIICharacterCheckerTest.java | 6 +++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cf5f072c5e..7b76805398e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where attempting to cancel the importing/generation of an entry from id is ignored. [#10508](https://github.com/JabRef/jabref/issues/10508) - We fixed an issue where the preview panel showing the wrong entry (an entry that is not selected in the entry table). [#9172](https://github.com/JabRef/jabref/issues/9172) +- We fixed an issue where the duplicate check ### Removed diff --git a/src/main/java/org/jabref/logic/database/DuplicateCheck.java b/src/main/java/org/jabref/logic/database/DuplicateCheck.java index 3090c9a8778..f2858bb46b7 100644 --- a/src/main/java/org/jabref/logic/database/DuplicateCheck.java +++ b/src/main/java/org/jabref/logic/database/DuplicateCheck.java @@ -154,14 +154,14 @@ private static double[] compareFieldSet(final Collection fields, final Bi } private static int compareSingleField(final Field field, final BibEntry one, final BibEntry two) { - final Optional optionalStringOne = one.getField(field); - final Optional optionalStringTwo = two.getField(field); - if (!optionalStringOne.isPresent()) { - if (!optionalStringTwo.isPresent()) { + final Optional optionalStringOne = one.getFieldLatexFree(field); + final Optional optionalStringTwo = two.getFieldLatexFree(field); + if (optionalStringOne.isEmpty()) { + if (optionalStringTwo.isEmpty()) { return EMPTY_IN_BOTH; } return EMPTY_IN_ONE; - } else if (!optionalStringTwo.isPresent()) { + } else if (optionalStringTwo.isEmpty()) { return EMPTY_IN_TWO; } diff --git a/src/test/java/org/jabref/logic/database/DuplicateCheckTest.java b/src/test/java/org/jabref/logic/database/DuplicateCheckTest.java index 8c644ab40f2..3eafdecae26 100644 --- a/src/test/java/org/jabref/logic/database/DuplicateCheckTest.java +++ b/src/test/java/org/jabref/logic/database/DuplicateCheckTest.java @@ -77,6 +77,14 @@ public void testDuplicateDetectionWithSameAuthor() { assertTrue(duplicateChecker.isDuplicate(one, two, BibDatabaseMode.BIBTEX)); } + @Test + public void testDuplicateDetectionWithSameAuthorAndUmlauts() { + BibEntry one = new BibEntry(StandardEntryType.Article).withField(StandardField.AUTHOR, "Billy Bobä"); + BibEntry two = new BibEntry(StandardEntryType.Article).withField(StandardField.AUTHOR, "Bill{\\\"{a}} Bob{\\\"{a}}"); + + assertTrue(duplicateChecker.isDuplicate(one, two, BibDatabaseMode.BIBTEX)); + } + @Test public void testDuplicateDetectionWithDifferentAuthors() { diff --git a/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java b/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java index 09efadebe2d..9dbefceb61c 100644 --- a/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/ASCIICharacterCheckerTest.java @@ -35,11 +35,11 @@ void fieldDoesNotAcceptUnicode() { @Test void fieldAcceptsOnlyAsciiCharacters() { - String field = ""; + StringBuilder field = new StringBuilder(); for (int i = 32; i <= 127; i++) { - field += Character.toString(i); + field.append(Character.toString(i)); } - entry.setField(StandardField.TITLE, field); + entry.setField(StandardField.TITLE, field.toString()); assertEquals(Collections.emptyList(), checker.check(entry)); } From 1fb8e0f7fbed636e426b73819b919b83703fc239 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Wed, 3 Jan 2024 16:52:14 +0100 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b76805398e..5e0a36fd3f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where attempting to cancel the importing/generation of an entry from id is ignored. [#10508](https://github.com/JabRef/jabref/issues/10508) - We fixed an issue where the preview panel showing the wrong entry (an entry that is not selected in the entry table). [#9172](https://github.com/JabRef/jabref/issues/9172) -- We fixed an issue where the duplicate check +- We fixed an issue where the duplicate check did not take umlauts or other LaTeX-encoded characters into account [#10744](https://github.com/JabRef/jabref/pull/10744) ### Removed From d6f74d17894544f0ab365a497849014c9794bc32 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Wed, 3 Jan 2024 17:07:03 +0100 Subject: [PATCH 3/3] checkstyle --- src/test/java/org/jabref/logic/database/DuplicateCheckTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/database/DuplicateCheckTest.java b/src/test/java/org/jabref/logic/database/DuplicateCheckTest.java index 3eafdecae26..39741898087 100644 --- a/src/test/java/org/jabref/logic/database/DuplicateCheckTest.java +++ b/src/test/java/org/jabref/logic/database/DuplicateCheckTest.java @@ -77,6 +77,7 @@ public void testDuplicateDetectionWithSameAuthor() { assertTrue(duplicateChecker.isDuplicate(one, two, BibDatabaseMode.BIBTEX)); } + @Test public void testDuplicateDetectionWithSameAuthorAndUmlauts() { BibEntry one = new BibEntry(StandardEntryType.Article).withField(StandardField.AUTHOR, "Billy Bobä"); @@ -85,7 +86,6 @@ public void testDuplicateDetectionWithSameAuthorAndUmlauts() { assertTrue(duplicateChecker.isDuplicate(one, two, BibDatabaseMode.BIBTEX)); } - @Test public void testDuplicateDetectionWithDifferentAuthors() { BibEntry one = new BibEntry(StandardEntryType.Article).withField(StandardField.AUTHOR, "Billy Bob");