diff --git a/CHANGELOG.md b/CHANGELOG.md index e57071da6c6..c19bebd67ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - It is now possible to add your own lists of protected terms, see Options -> Manage protected terms - Automatically generated group names are now converted from LaTeX to Unicode - Unified dialogs for opening/saving files +- Add integrity check to avoid non-ASCII characters in BibTeX files ### Fixed - Fixed [#1632](https://github.com/JabRef/jabref/issues/1632): User comments (@Comment) with or without brackets are now kept diff --git a/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java b/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java index 022694ec337..0a8756a422e 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java +++ b/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java @@ -23,6 +23,8 @@ import net.sf.jabref.model.entry.InternalBibtexFields; import net.sf.jabref.model.entry.ParsedFileField; +import com.google.common.base.CharMatcher; + public class IntegrityCheck { private final BibDatabaseContext bibDatabaseContext; @@ -50,9 +52,11 @@ private List checkBibtexEntry(BibEntry entry) { result.addAll(new AuthorNameChecker().check(entry)); + // BibTeX only checkers if (!bibDatabaseContext.isBiblatexMode()) { result.addAll(new TitleChecker().check(entry)); result.addAll(new PagesChecker().check(entry)); + result.addAll(new ASCIICharacterChecker().check(entry)); } else { result.addAll(new BiblatexPagesChecker().check(entry)); } @@ -394,7 +398,6 @@ private static class BibStringChecker implements Checker { // Detect # if it doesn't have a \ in front of it or if it starts the string private static final Pattern UNESCAPED_HASH = Pattern.compile("(? check(BibEntry entry) { } } + private static class ASCIICharacterChecker implements Checker { + /** + * Detect any non ASCII encoded characters, e.g., umlauts or unicode in the fields + */ + @Override + public List check(BibEntry entry) { + List results = new ArrayList<>(); + for (Map.Entry field : entry.getFieldMap().entrySet()) { + boolean asciiOnly = CharMatcher.ascii().matchesAllOf(field.getValue()); + if (!asciiOnly) { + results.add(new IntegrityMessage(Localization.lang("Non-ASCII encoded character found"), entry, + field.getKey())); + } + } + return results; + } + } + } diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index 0e2a6f94384..e7517cff11c 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -1750,3 +1750,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index a06ff83125d..51f2900c130 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -2460,3 +2460,5 @@ Open_OpenOffice/LibreOffice_connection=Öffne_OpenOffice/LibreOffice_Verbindung You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 4bd3ea3f50a..f6a820026cb 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2288,3 +2288,4 @@ Style_file=Style_file Open_OpenOffice/LibreOffice_connection=Open_OpenOffice/LibreOffice_connection You_must_enter_at_least_one_field_name=You_must_enter_at_least_one_field_name +Non-ASCII_encoded_character_found=Non-ASCII_encoded_character_found \ No newline at end of file diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index 26e0916ff6c..8c1fded648f 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -1651,3 +1651,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index ec89791b8a6..987d8b74ce2 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -2432,3 +2432,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index e5d7f4e9e17..dfd1e2a2fb6 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -1692,3 +1692,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index b891d701620..99f6e952d62 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -1667,3 +1667,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index a431f23c4a4..78fb92a178b 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -1768,3 +1768,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index 7f5958734ce..df7a9f40909 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -2409,3 +2409,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index 11fb450036d..fa8be0a94a8 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -2441,3 +2441,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index af06728e3a5..f9d61e43bdf 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -2833,3 +2833,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index 7a5d476c8b5..01f636a4487 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -1664,3 +1664,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index 400e085a01f..8e3e2d7bc49 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -2410,3 +2410,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_sv.properties b/src/main/resources/l10n/JabRef_sv.properties index a66a3b915f8..e1a1549416f 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -1609,3 +1609,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index e4a6841ac0f..6c42830e3a6 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -1682,3 +1682,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index c643c9d31e7..09b302dc40b 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -2436,3 +2436,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index 95f1f05b8fc..0b669acab95 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -1676,3 +1676,5 @@ Open_OpenOffice/LibreOffice_connection= You_must_enter_at_least_one_field_name= + +Non-ASCII_encoded_character_found= diff --git a/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java b/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java index 29f73162639..354d2a65bd1 100644 --- a/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java @@ -213,6 +213,13 @@ public void testISBNChecks() { assertWrong(createContext("isbn", "978-0-306-40615-8")); } + @Test + public void testASCIIChecks() { + assertCorrect(createContext("title", "Only ascii characters!'@12")); + assertWrong(createContext("month", "Umlauts are nöt ällowed")); + assertWrong(createContext("author", "Some unicode ⊕")); + } + private BibDatabaseContext createContext(String field, String value, String type) { BibEntry entry = new BibEntry(); entry.setField(field, value);