From d8ec439bedad774cec7408bb222cce265603a887 Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Tue, 13 Sep 2016 13:21:29 +0200 Subject: [PATCH] Fixes #1958: Verbatim URL field is no longer checked for HTML encoded chars (#1970) --- CHANGELOG.md | 1 + .../jabref/logic/integrity/HTMLCharacterChecker.java | 11 ++++++++--- .../java/net/sf/jabref/model/entry/FieldName.java | 3 --- .../sf/jabref/logic/integrity/IntegrityCheckTest.java | 1 + 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57562154a8f..cff84bdce1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - Fixed [#1949](https://github.com/JabRef/jabref/issues/1949): Error message directs to the wrong preference tab - Fixed InvalidBackgroundColor flickering with Ctrl-s and File > Save database - Fixed loop when pulling changes (shared database) when current selected field has changed +- Fixed [#1958](https://github.com/JabRef/jabref/issues/1958): Verbatim fields are no longer checked for HTML encoded characters by integrity checks ### Removed - The non-supported feature of being able to define file directories for any extension is removed. Still, it should work for older databases using the legacy `ps` and `pdf` fields, although we strongly encourage using the `file` field. diff --git a/src/main/java/net/sf/jabref/logic/integrity/HTMLCharacterChecker.java b/src/main/java/net/sf/jabref/logic/integrity/HTMLCharacterChecker.java index 8e9a20f288d..e9be617944f 100644 --- a/src/main/java/net/sf/jabref/logic/integrity/HTMLCharacterChecker.java +++ b/src/main/java/net/sf/jabref/logic/integrity/HTMLCharacterChecker.java @@ -9,20 +9,25 @@ import net.sf.jabref.logic.integrity.IntegrityCheck.Checker; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.model.entry.FieldProperty; +import net.sf.jabref.model.entry.InternalBibtexFields; public class HTMLCharacterChecker implements Checker { - // Detect any HTML encoded character, private static final Pattern HTML_CHARACTER_PATTERN = Pattern.compile("&[#\\p{Alnum}]+;"); - /** - * Checks, if there are any HTML encoded characters in the fields + * Checks, if there are any HTML encoded characters in nonverbatim fields. */ @Override public List check(BibEntry entry) { List results = new ArrayList<>(); for (Map.Entry field : entry.getFieldMap().entrySet()) { + // skip verbatim fields + if (InternalBibtexFields.getFieldProperties(field.getKey()).contains(FieldProperty.VERBATIM)) { + continue; + } + Matcher characterMatcher = HTML_CHARACTER_PATTERN.matcher(field.getValue()); if (characterMatcher.find()) { results.add( diff --git a/src/main/java/net/sf/jabref/model/entry/FieldName.java b/src/main/java/net/sf/jabref/model/entry/FieldName.java index c5563bc0381..8f92841fdf4 100644 --- a/src/main/java/net/sf/jabref/model/entry/FieldName.java +++ b/src/main/java/net/sf/jabref/model/entry/FieldName.java @@ -10,7 +10,6 @@ * */ public class FieldName { - // Character separating field names that are to be used in sequence as // fallbacks for a single column (e.g. "author/editor" to use editor where // author is not set): @@ -128,7 +127,6 @@ public class FieldName { // Map to hold alternative display names private static final Map displayNames = new HashMap<>(); - public static String orFields(String... fields) { return String.join(FieldName.FIELD_SEPARATOR, fields); } @@ -149,7 +147,6 @@ public static String orFields(List fields) { displayNames.put(FieldName.URL, "URL"); } - /** * @param field - field to get the display version for * @return A version of the field name more suitable for display 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 e3a03fe4648..1d921004879 100644 --- a/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java +++ b/src/test/java/net/sf/jabref/logic/integrity/IntegrityCheckTest.java @@ -225,6 +225,7 @@ public void testHTMLCharacterChecks() { assertCorrect(createContext("title", "Not a single {HTML} character")); assertCorrect(createContext("month", "#jan#")); assertCorrect(createContext("author", "A. Einstein and I. Newton")); + assertCorrect(createContext("url", "http://www.thinkmind.org/index.php?view=article&articleid=cloud_computing_2013_1_20_20130")); assertWrong(createContext("author", "Lenhard, Jörg")); assertWrong(createContext("author", "Lenhard, Jãrg")); assertWrong(createContext("journal", "Ärling Ström for – ‱"));