Skip to content

Commit

Permalink
Add an integrity check to ensure that a url has a correct protocol, i…
Browse files Browse the repository at this point in the history
…mplements #358
  • Loading branch information
simonharrer committed Jan 8, 2016
1 parent 17a06b3 commit 956ddfa
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/sf/jabref/logic/integrity/IntegrityCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntegrityMessage> checkBibtexDatabase(BibDatabase base) {
List<IntegrityMessage> result = new ArrayList<>();
Expand Down Expand Up @@ -69,6 +70,11 @@ public List<IntegrityMessage> 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;
}

Expand All @@ -77,6 +83,16 @@ public interface Checker {
void check(String value, String fieldName, BibEntry entry, List<IntegrityMessage> collector);
}

private static class UrlChecker implements Checker {

@Override
public void check(String value, String fieldName, BibEntry entry, List<IntegrityMessage> collector) {
if(!value.contains("://")) {
collector.add(new IntegrityMessage(Localization.lang("should contain a protocol") + ": http[s]://, file:// or ftp://", entry, fieldName));

This comment has been minimized.

Copy link
@tobiasdiez

tobiasdiez Jan 8, 2016

Member

@simonharrer: the or is not translated :-)

This comment has been minimized.

Copy link
@simonharrer

simonharrer Jan 9, 2016

Author Contributor

ah, good point. :) I think for simplicity reasons I will just convert the 'or' to a comma :)

}
}
}

private static class AuthorNameChecker implements Checker {

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1728,3 +1728,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1628,3 +1628,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2415,3 +2415,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1648,3 +1648,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1746,3 +1746,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2420,3 +2420,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2422,3 +2422,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2821,3 +2821,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1641,3 +1641,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2421,3 +2421,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1662,3 +1662,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2419,3 +2419,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2416,3 +2416,5 @@ Synchronize_files=
Unabbreviate=

Error_occured_parsing_Bibtex_returned_from_IEEEXplore=

should_contain_a_protocol=
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 956ddfa

Please sign in to comment.