Skip to content

Commit

Permalink
Support two argument form of \abx@aux@cite macro in DefaultAuxParser (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Insomniac66 authored Mar 7, 2022
1 parent 3c381bb commit b304feb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where "Copy DOI url" in the right-click menu of the Entry List would just copy the DOI and not the DOI url. [#8389](https://github.com/JabRef/jabref/issues/8389)
- We fixed an issue where opening the console from the drop-down menu would cause an exception. [#8466](https://github.com/JabRef/jabref/issues/8466)
- We fixed an issue where pasting a URL was replacing + signs by spaces making the URL unreachable. [#8448](https://github.com/JabRef/jabref/issues/8448)
- We fixed an issue where creating subsidiary files from aux files created with some versions of biblatex would produce incorrect results. [#8513](https://github.com/JabRef/jabref/issues/8513)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class DefaultAuxParser implements AuxParser {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAuxParser.class);

private static final Pattern CITE_PATTERN = Pattern.compile("\\\\(citation|abx@aux@cite)\\{(.+)\\}");
private static final Pattern CITE_PATTERN = Pattern.compile("\\\\(citation|abx@aux@cite)(\\{\\d+\\})?\\{(?<citationkey>.+)\\}");
private static final Pattern INPUT_PATTERN = Pattern.compile("\\\\@input\\{(.+)\\}");

private final BibDatabase masterDatabase;
Expand Down Expand Up @@ -108,7 +108,7 @@ private void matchCitation(AuxParserResult result, String line) {
Matcher citeMatch = CITE_PATTERN.matcher(line);

while (citeMatch.find()) {
String keyString = citeMatch.group(2);
String keyString = citeMatch.group("citationkey");
String[] keys = keyString.split(",");

for (String key : keys) {
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/org/jabref/logic/auxparser/AuxParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ void testNormal() throws URISyntaxException, IOException {
}
}

@Test
void testTwoArgMacro() throws URISyntaxException, IOException {
// Result should be identical to that of testNormal

InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Path auxFile = Path.of(AuxParserTest.class.getResource("papertwoargmacro.aux").toURI());
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader);

AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
AuxParserResult auxResult = auxParser.parse(auxFile);

assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());
assertEquals(0, auxResult.getUnresolvedKeysCount());
BibDatabase newDB = auxResult.getGeneratedBibDatabase();
List<BibEntry> newEntries = newDB.getEntries();
assertEquals(2, newEntries.size());
assertTrue(newEntries.get(0).hasChanged());
assertTrue(newEntries.get(1).hasChanged());
assertEquals(2, auxResult.getResolvedKeysCount());
assertEquals(2, auxResult.getFoundKeysInAux());
assertEquals(auxResult.getFoundKeysInAux() + auxResult.getCrossRefEntriesCount(),
auxResult.getResolvedKeysCount() + auxResult.getUnresolvedKeysCount());
assertEquals(0, auxResult.getCrossRefEntriesCount());
}
}

@Test
void testNotAllFound() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
\relax
\abx@aux@cite{0}{Darwin1888}
\abx@aux@cite{0}{Einstein1920}
\bibstyle{plain}
\bibdata{origin}
\bibcite{Darwin1888}{1}
\bibcite{Einstein1920}{2}
\@writefile{toc}{\contentsline {section}{\numberline {1}}{1}}

0 comments on commit b304feb

Please sign in to comment.