Skip to content

Commit

Permalink
Consider empty brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
btut committed May 12, 2020
1 parent 5861685 commit 230fef2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ public static String expandBrackets(String pattern, Character keywordDelimiter,
// FIXME: else -> raise exception or log? (S.G.)
} else {
if ("[".equals(token)) {
Boolean foundClosingBracket = false;
// Fetch the next token after the '[':
token = st.nextToken();
Boolean foundClosingBracket = false;
if ("]".equals(token)) {
LOGGER.warn("Found empty brackets \"[]\" in '" + pattern + "'");
foundClosingBracket = true;
}
// make sure to read until the next ']'
while (st.hasMoreTokens()) {
while (st.hasMoreTokens() && !foundClosingBracket) {
String subtoken = st.nextToken();
// I the beginning of a quote is found, include the content in the original token
if ("\"".equals(subtoken)) {
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/jabref/logic/util/BracketedPatternTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,10 @@ void regularExpressionWithBrackets() {
assertEquals("2003-JabRef Science",
BracketedPattern.expandBrackets("[year]-[journal:regex(\"[OX]rganization\",\"JabRef\")]", ';', dbentry, database));
}

@Test
void testEmptyBrackets() {
assertEquals("2003-Organization Science",
BracketedPattern.expandBrackets("[year][]-[journal]", ';', dbentry, database));
}
}

0 comments on commit 230fef2

Please sign in to comment.