From 956ddfaf13db2f375ecbf13c3cf77202c5ae5a85 Mon Sep 17 00:00:00 2001 From: Simon Harrer Date: Fri, 8 Jan 2016 16:28:38 +0100 Subject: [PATCH] Add an integrity check to ensure that a url has a correct protocol, implements #358 --- CHANGELOG.md | 1 + .../jabref/logic/integrity/IntegrityCheck.java | 16 ++++++++++++++++ src/main/resources/l10n/JabRef_da.properties | 2 ++ src/main/resources/l10n/JabRef_de.properties | 2 ++ src/main/resources/l10n/JabRef_en.properties | 1 + src/main/resources/l10n/JabRef_es.properties | 2 ++ src/main/resources/l10n/JabRef_fa.properties | 2 ++ src/main/resources/l10n/JabRef_fr.properties | 2 ++ src/main/resources/l10n/JabRef_in.properties | 2 ++ src/main/resources/l10n/JabRef_it.properties | 2 ++ src/main/resources/l10n/JabRef_ja.properties | 2 ++ src/main/resources/l10n/JabRef_nl.properties | 2 ++ src/main/resources/l10n/JabRef_no.properties | 2 ++ src/main/resources/l10n/JabRef_pt_BR.properties | 2 ++ src/main/resources/l10n/JabRef_ru.properties | 2 ++ src/main/resources/l10n/JabRef_tr.properties | 2 ++ src/main/resources/l10n/JabRef_vi.properties | 2 ++ src/main/resources/l10n/JabRef_zh.properties | 2 ++ .../logic/integrity/IntegrityCheckTest.java | 10 ++++++++++ 19 files changed, 58 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 861108c69d7..01729740af5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by ### Changed - All import/open database warnings are now shown in a scrolling text area +- Add an integrity check to ensure that a url has a correct protocol, implements #358 ### Fixed - Changes in customized entry types are now directly reflected in the table when clicking "Apply" or "OK" 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 986a8fe94c8..e4b15e9eb66 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java +++ b/src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java @@ -19,6 +19,7 @@ public class IntegrityCheck { public static final Checker TITLE_CHECKER = new TitleChecker(); public static final Checker BRACKET_CHECKER = new BracketChecker(); public static final Checker PAGES_CHECKER = new PagesChecker(); + public static final Checker URL_CHECKER = new UrlChecker(); public List checkBibtexDatabase(BibDatabase base) { List result = new ArrayList<>(); @@ -69,6 +70,11 @@ public List checkBibtexEntry(BibEntry entry) { PAGES_CHECKER.check(data.toString(), "pages", entry, result); } + data = entry.getField("url"); + if (data != null) { + URL_CHECKER.check(data.toString(), "url", entry, result); + } + return result; } @@ -77,6 +83,16 @@ public interface Checker { void check(String value, String fieldName, BibEntry entry, List collector); } + private static class UrlChecker implements Checker { + + @Override + public void check(String value, String fieldName, BibEntry entry, List collector) { + if(!value.contains("://")) { + collector.add(new IntegrityMessage(Localization.lang("should contain a protocol") + ": http[s]://, file:// or ftp://", entry, fieldName)); + } + } + } + private static class AuthorNameChecker implements Checker { @Override diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index 2e4689842a8..6910797c110 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -1728,3 +1728,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index db87c4f3e34..5d282f47860 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -2437,3 +2437,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore=Problem_beim_Analysieren_des_von_IEEEXplore_empfangenen_Eintrags + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index c31766fe61c..a7ccd66d187 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2424,3 +2424,4 @@ Switch_preview_layout=Switch_preview_layout Synchronize_files=Synchronize_files Unabbreviate=Unabbreviate Error_occured_parsing_Bibtex_returned_from_IEEEXplore=Error_occured_parsing_Bibtex_returned_from_IEEEXplore +should_contain_a_protocol=should_contain_a_protocol \ 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 ba0acea3460..fb30fb2a3de 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -1628,3 +1628,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index b45492eb15c..1567f80f7c7 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -2415,3 +2415,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index 4fbdc22cd26..9aa6e8dac80 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -1667,3 +1667,5 @@ Synchronize_files=Synchroniser_les_fichiers Unabbreviate=Dés-abréger Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index 5e353e9f70c..16f1f18aa8b 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -1648,3 +1648,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index 22384e4a0a6..c7e15bfeaa4 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -1746,3 +1746,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index 87328025a85..c5c64cd4983 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -2420,3 +2420,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index eb916f3958c..1c3f981ae0e 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -2422,3 +2422,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index 2d6a281bd39..7ca6ef8645d 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -2821,3 +2821,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index 926649113fa..f6ec3687419 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -1641,3 +1641,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index a822ca45b4e..6fae1abd0ea 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -2421,3 +2421,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index 9c3e72cbf50..93f7879091e 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -1662,3 +1662,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index 404a7635a94..7613b23d04d 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -2419,3 +2419,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index 5b65ad0f426..3b9f2dbdc48 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -2416,3 +2416,5 @@ Synchronize_files= Unabbreviate= Error_occured_parsing_Bibtex_returned_from_IEEEXplore= + +should_contain_a_protocol= 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 c0d3c8ba002..2e35a3cce4f 100644 --- a/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java @@ -13,6 +13,16 @@ public class IntegrityCheckTest { + @Test + public void testUrlChecks() { + assertCorrect("http://www.google.com", IntegrityCheck.URL_CHECKER); + assertCorrect("https://www.google.com", IntegrityCheck.URL_CHECKER); + assertCorrect("file://c:/asdf/asdf", IntegrityCheck.URL_CHECKER); + assertWrong("www.google.com", IntegrityCheck.URL_CHECKER); + assertWrong("google.com", IntegrityCheck.URL_CHECKER); + assertWrong("c:/asdf/asdf", IntegrityCheck.URL_CHECKER); + } + @Test public void testYearChecks() { assertCorrect("2014", IntegrityCheck.YEAR_CHECKER);