Skip to content

Commit

Permalink
Strip invalid prolog when loading CitationStyles (JabRef#3404)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhard authored and LinusDietz committed Nov 5, 2017
1 parent 8925c1f commit ab517f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed several issues with the automatic linking of files in the entry editor where files were not found or not correctly saved in the bibtex source [#3346](https://github.com/JabRef/jabref/issues/3346)
- We fixed an issue where fetching entries from crossref that had no titles caused an error [#3376](https://github.com/JabRef/jabref/issues/3376)
- We fixed an issue where the same Java Look and Feel would be listed more than once in the Preferences. [#3391](https://github.com/JabRef/jabref/issues/3391)
- We fixed an issue where errors in citation styles triggered an exception when opening the preferences dialog [#3389](https://github.com/JabRef/jabref/issues/3389)

### Removed

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/jabref/logic/citationstyle/CitationStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ private CitationStyle(final String filename, final String title, final String so
* Creates an CitationStyle instance out of the style string
*/
private static CitationStyle createCitationStyleFromSource(final String source, final String filename) {
if (source != null && !source.isEmpty() && filename != null && !filename.isEmpty()) {
if (filename != null && !filename.isEmpty() && source != null && !source.isEmpty()) {
try {
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(source));
is.setCharacterStream(new StringReader(stripInvalidProlog(source)));

Document doc = db.parse(is);
NodeList nodes = doc.getElementsByTagName("info");
Expand All @@ -78,6 +78,15 @@ private static CitationStyle createCitationStyleFromSource(final String source,
return null;
}

private static String stripInvalidProlog(String source) {
int startIndex = source.indexOf("<");
if (startIndex > 0) {
return source.substring(startIndex, source.length());
} else {
return source;
}
}

/**
* Loads the CitationStyle from the given file
*/
Expand Down

0 comments on commit ab517f4

Please sign in to comment.