Skip to content

Commit

Permalink
Fixes JabRef#1958: Verbatim URL field is no longer checked for HTML e…
Browse files Browse the repository at this point in the history
…ncoded chars (JabRef#1970)
  • Loading branch information
stefan-kolb authored and zesaro committed Oct 27, 2016
1 parent 11dd5d7 commit b3f1414
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntegrityMessage> check(BibEntry entry) {
List<IntegrityMessage> results = new ArrayList<>();
for (Map.Entry<String, String> 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(
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/net/sf/jabref/model/entry/FieldName.java
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -134,7 +133,6 @@ public class FieldName {
// Map to hold alternative display names
private static final Map<String, String> displayNames = new HashMap<>();


public static String orFields(String... fields) {
return String.join(FieldName.FIELD_SEPARATOR, fields);
}
Expand All @@ -155,7 +153,6 @@ public static String orFields(List<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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&amp;articleid=cloud_computing_2013_1_20_20130"));
assertWrong(createContext("author", "Lenhard, J&ouml;rg"));
assertWrong(createContext("author", "Lenhard, J&#227;rg"));
assertWrong(createContext("journal", "&Auml;rling Str&ouml;m for &#8211; &#x2031;"));
Expand Down

0 comments on commit b3f1414

Please sign in to comment.